Computer Networks Practical File
Computer Networks Practical File
PRACTICAL FILE
COMPUTER NETWORKS - LAB
BCS653
(EVEN SEMESTER)
SUBMITTED BY:
Submitted by :
Roll no :
Course :
Brance
Section :
Year :
Semester :
SUBMITTED TO:
Department : CSE
Page 1 of 51
INDEX PAGE
Contents
NETWORKING COMMANDS: ............................................................................................ 5
1. IPCONFIG Commands: ................................................................................................. 5
2. PING Command:............................................................................................................ 6
3. TRACERT Command: ................................................................................................... 7
4. NSLOOKUP Commands: ............................................................................................... 8
5. GETMAC Command:..................................................................................................... 9
6. NETSTAT Command: .................................................................................................. 10
[Link] Command: ............................................................................................... 12
8. ARP Command: ........................................................................................................... 13
9. SYSTEMINFO Command: ........................................................................................... 14
10. ROUTE Command: .................................................................................................... 15
Batch Programming (Windows) ......................................................................................... 17
What is Batch Programming? ..................................................................................... 17
Common Commands .............................................................................................. 17
Variables................................................................................................................. 17
User Input ............................................................................................................... 17
Conditional Statements ........................................................................................... 17
Labels and Goto ...................................................................................................... 18
Loops using for...................................................................................................... 18
Error Handling ......................................................................................................... 18
File Operations........................................................................................................ 18
Useful Tips .............................................................................................................. 18
Saving and Running ................................................................................................. 19
Q1: Write a program in batch to perform all arithmetic operations: .................................. 20
Q2: Write a program in batch to perform all arithmetic operations through function: ........ 21
Q3: Write a program to perform sum and multiplication of series from 1 to N by using
Function: ......................................................................................................................... 22
Q3: Write a program to find factorial of given number? .................................................... 23
Q4: Write a program to print table of given number; ........................................................ 24
Q5: Write a program to print pattern: .............................................................................. 25
Q6: Write a program to print pattern second. ................................................................... 26
Page 2 of 51
Q7: Write a program to print pattern third ....................................................................... 27
CLIENT/SERVER ARCHITECTURE: ................................................................................ 29
Client/Server Socket Connection Diagram: ....................................................................... 30
TCP PROGRAMMING IN JAVA: ................................................................................... 31
UDP Programming Through Java ................................................................................... 32
UDP Communication in Java Requires: ........................................................................ 32
Step-by-Step Example: Java UDP Client-Server ............................................................ 32
1. UDP Server Code ................................................................................................. 32
2. UDP Client Code.................................................................................................. 33
NETWORKING TOOLS: ...................................................................................................... 35
1. CRIMPLING TOOL: ................................................................................................... 35
2. LAN CABLE TESTER: .................................................................................................. 35
3.RJ45 Connector:............................................................................................................ 36
DIFFERENCE BETWEEN STRAIGHT AND CROSSOVER CABLE: ............................. 37
1. Straight Through Cable......................................................................................... 37
2. Crossover Cable .................................................................................................. 37
Summary Table: ...................................................................................................... 38
CISCO PACKET TRACER: ................................................................................................ 40
What is Cisco Packet Tracer? ........................................................................................ 40
1. Download and Install ........................................................................................... 40
2. Interface Overview ............................................................................................... 40
3. Create a Simple Network ..................................................................................... 40
4. Test Connection (Ping) ......................................................................................... 41
5. Add Router and Configure Interfaces .................................................................... 41
6. Basic CLI Commands .......................................................................................... 41
Simulation Mode......................................................................................................... 42
Practice Ideas ............................................................................................................. 42
Steps to Configure and Verify Three Router Connections in Cisco Packet Tracer using RIP
Routing:........................................................................................................................... 43
Page 3 of 51
Page 4 of 51
NETWORKING COMMANDS:
1. IPCONFIG Commands:
The ipconfig command is used in Windows to view and manage the IP configuration of your
computer. Below are some commonly used ipconfig commands:
Command Description
ipconfig Displays basic IP address, subnet mask, and default gateway for all adapters.
Command Description
ipconfig /release Releases the current IP address from the network adapter.
ipconfig /registerdns Refreshes all DHCP leases and re-registers DNS names.
Usage Examples
ipconfig /all
Fix connectivity issues (renew IP)
ipconfig /release
ipconfig /renew
ipconfig /flushdns
Page 5 of 51
2. PING Command:
Here are the commonly used ping commands in Windows OS, used to test network
connectivity and diagnose issues:
Command Description
Example:
ping [Link]
ping [Link]
Command Description
ping -n <count>
<host>
Sends a specific number of pings.
ping -l <size>
<host>
Sends a ping packet of a specific byte size (default is 32 bytes).
Page 6 of 51
3. TRACERT Command:
The tracert command (short for Trace Route) in Windows OS is used to trace the path
packets take from your computer to a destination host. It helps identify network delays or
connection failures between routers.
Command Description
tracert <hostname or IP> Traces the route taken by packets to reach a destination.
Example:
tracert [Link]
Command Description
tracert -w <timeout> <host> Set timeout in milliseconds to wait for each reply.
Use Case
Page 7 of 51
4. NSLOOKUP Commands:
The nslookup (Name Server Lookup) command in Windows OS is used to query DNS
servers and troubleshoot domain name resolution issues. It helps you find the IP address of
a domain or the domain name of an IP address.
Command Description
Example:
nslookup [Link]
Command Description
Basic domain to IP
nslookup [Link]
Reverse IP to domain
nslookup [Link]
Use a specific DNS server (e.g., Cloudflare)
nslookup [Link] [Link]
Page 8 of 51
5. GETMAC Command:
The getmac command in Windows OS is used to display the MAC addresses of your
computer's network adapters.
Basic Command
getmac
This shows:
Command Description
getmac /fo
list
Displays output in a list format.
getmac /fo
table
Displays output in a table format (default).
getmac /fo
csv
Displays output in CSV (comma-separated) format.
getmac /nh Hides the column headers in output (use with /fo).
Examples
Tip:
Page 9 of 51
6. NETSTAT Command:
The netstat command (Network Statistics) in Windows OS is used to display active
network connections, ports, and various networking statistics. It's especially useful for
diagnosing network issues and identifying open ports or suspicious activity.
Basic Command
netstat
Command Description
netstat -n Shows addresses and ports in numeric format (no DNS lookup).
netstat -
anob
Combines multiple options: numeric + process ID + binary (app names).
Page 10 of 51
Combine with tasklist to Identify Programs by PID
After using:
netstat -ano
You can match the PID (last column) with the program name:
tasklist /fi "PID eq 1234"
Page 11 of 51
[Link] Command:
hostname Command in Windows
The hostname command in Windows is used to display the name of the current computer
(i.e., the hostname of the machine on the network).
Syntax:
hostname
Example Output:
C:\Users\Kapil>hostname
DESKTOP-ABC123
Use Case:
You cannot change the hostname using the hostname command. Instead, do one of the
following:
GUI Method:
Page 12 of 51
8. ARP Command:
arp Command in Windows
The arp (Address Resolution Protocol) command in Windows is used to view and manage
the ARP cache, which stores mappings of IP addresses to MAC (physical) addresses on a
local network.
Syntax:
arp [command] [options]
Command Description
Example Usage:
Note:
• The ARP cache stores entries temporarily unless manually added with -s.
• Use arp -a often when troubleshooting LAN connectivity or checking if a device is
reachable.
Page 13 of 51
9. SYSTEMINFO Command:
systeminfo Command in Windows
Basic Syntax:
systeminfo
• Host Name
• Domain
• Logon Server
• Network Card(s):
o Description (e.g., Intel Ethernet, Wi-Fi)
o MAC Address
o DHCP Enabled
o IP Address(es)
o Subnet Mask
o Default Gateway
Page 14 of 51
10. ROUTE Command:
In Windows, the route command is a powerful networking utility used to view and
manipulate the IP routing table. It allows you to add, delete, and print network routes.
Basic Syntax:
route [command] [destination] [mask subnet_mask] [gateway] [metric metric]
[if interface]
Common route Commands in Windows:
Command Description
Examples:
Delete a Route
route delete [Link]
Modify a Route
route change [Link] mask [Link] [Link]
Notes:
• Use -p only with the add command to make the route persistent.
• You may need Administrator privileges to use route add, delete, or change.
Page 15 of 51
BATCH SCRIPT
PROGRAMMING
Page 16 of 51
📘 Batch Programming (Windows)
🔹 What is Batch Programming?
Batch programming involves writing a series of commands in a .bat or .cmd file to
automate tasks in Windows Command Prompt (CMD).
Basic Structure
@echo off
REM This is a comment
echo Hello, World!
pause
🔹 Common Commands
Command Description
if Conditional statement
🔹 Variables
set name=Kapil
echo Hello %name%
🔹 User Input
set /p username=Enter your name:
echo Hello, %username%
🔹 Conditional Statements
if %name%==Kapil echo Welcome, Kapil!
Page 17 of 51
🔹 Labels and Goto
:menu
echo 1. Say Hello
echo 2. Exit
set /p choice=Choose:
if %choice%==1 goto hello
if %choice%==2 goto end
:hello
echo Hello!
goto menu
:end
exit
🔹 Error Handling
commandThatMightFail
if errorlevel 1 echo An error occurred
🔹 File Operations
Operation Example
🔹 Useful Tips
Page 18 of 51
🔹 Saving and Running
Page 19 of 51
Q1: Write a program in batch to perform all arithmetic
operations:
Page 20 of 51
Q2: Write a program in batch to perform all arithmetic
operations through function:
Page 21 of 51
Q3: Write a program to perform sum and multiplication of series
from 1 to N by using Function:
Page 22 of 51
Q3: Write a program to find factorial of given number?
OUTPUT:
Page 23 of 51
Q4: Write a program to print table of given number;
OUTPUT:
Page 24 of 51
Q5: Write a program to print pattern:
OUTPUT:
Page 25 of 51
Q6: Write a program to print pattern second.
OUTPUT:
Page 26 of 51
Q7: Write a program to print pattern third
OUTPUT:
Page 27 of 51
CLIENT/SERVER
ARCHITECTURE
Page 28 of 51
CLIENT/SERVER ARCHITECTURE:
Page 29 of 51
Client/Server Socket Connection Diagram:
Page 30 of 51
TCP PROGRAMMING IN JAVA:
// [Link]
import [Link].*;
import [Link].*;
[Link]();
} catch (Exception e) {
[Link](e);
}
}
}
// [Link]
import [Link].*;
import [Link].*;
Page 31 of 51
📘 UDP Programming Through Java
UDP (User Datagram Protocol) is a connectionless protocol that sends data in small packets
(datagrams). Unlike TCP, it doesn't guarantee delivery, ordering, or error checking, but it's
faster and lightweight, often used in real-time applications.
while (true) {
// Receive packet
DatagramPacket receivePacket = new
DatagramPacket(receiveBuffer, [Link]);
[Link](receivePacket);
String clientData = new String([Link](), 0,
[Link]());
[Link]("Received from client: " + clientData);
// Prepare reply
String reply = "Hello from server";
sendBuffer = [Link]();
// Send reply
InetAddress clientAddress = [Link]();
int clientPort = [Link]();
DatagramPacket sendPacket = new DatagramPacket(sendBuffer,
[Link], clientAddress, clientPort);
[Link](sendPacket);
}
}
}
Page 32 of 51
✅ 2. UDP Client Code
import [Link].*;
import [Link];
// Send packet
DatagramPacket sendPacket = new DatagramPacket(sendBuffer,
[Link], IPAddress, 9876);
[Link](sendPacket);
// Receive response
DatagramPacket receivePacket = new DatagramPacket(receiveBuffer,
[Link]);
[Link](receivePacket);
String serverReply = new String([Link](), 0,
[Link]());
[Link]("Reply from server: " + serverReply);
[Link]();
[Link]();
}
}
Key Points:
Feature Detail
Important Tips:
Page 33 of 51
NETWORKING TOOLS
Page 34 of 51
NETWORKING TOOLS:
1. CRIMPLING TOOL:
Page 35 of 51
3.RJ45 Connector:
Page 36 of 51
DIFFERENCE BETWEEN STRAIGHT AND CROSSOVER
CABLE:
Here's a clear comparison between Straight Through Cable and Crossover Cable, used in
computer networking:
Wiring Pattern Same at both ends (e.g., T568A to T568A or T568B to T568B)
Automatic Crossover
No
Needed?
🔁 2. Crossover Cable
Feature Description
Automatic Crossover
Yes, if not using crossover cable
Needed?
Page 37 of 51
🧠 Summary Table:
Feature Straight Cable Crossover Cable
Tip: Modern devices (since Gigabit Ethernet) often support Auto MDI/MDIX, which
means they can detect and adjust the connection type automatically making crossover cables
mostly obsolete.
Page 38 of 51
CISCO PACKET TRACER
SIMULATOR
Page 39 of 51
CISCO PACKET TRACER:
Cisco Packet Tracer, a powerful network simulation tool from Cisco used for learning
networking concepts and practicing configurations.
✅ 2. Interface Overview
Section Purpose
• 2 PCs
• 1 Switch
• Ethernet cables
Page 40 of 51
📦 Steps:
1. Add 2 PCs: Click End Devices → PC, then place on the workspace.
2. Add a Switch: Click Switches → Switch 2960.
3. Connect: Use Copper Straight-Through Cable to connect PC → Switch.
4. Assign IPs:
o Click PC → Desktop → IP Configuration
o Set:
▪ PC1: [Link] / [Link]
▪ PC2: [Link] / [Link]
Page 41 of 51
Command Description
🎥 Simulation Mode
1. Switch to Simulation Mode (bottom right).
2. Send ping packets and watch the data flow.
3. Useful for troubleshooting and protocol analysis.
📚 Practice Ideas
• Static Routing (2 routers, 2 networks)
• Dynamic Routing (RIP, OSPF)
• VLAN Configuration
• DHCP Server setup
• IoT Devices and Wireless Configuration
Page 42 of 51
Steps to Configure and Verify Three Router Connections in Cisco
Packet Tracer using RIP Routing:
Step 1: First, open the Cisco packet tracer desktop and select the devices given below:
1. PC PC 6
2. Switch PT-Switch 3
3. Router PT-router 3
IP Addressing Table:
Page 43 of 51
Step 2: Configure the PCs (hosts) with IPv4 address and Subnet Mask according to the IP
addressing table given above.
Then, go to desktop and then IP configuration and there you will IPv4 configuration.
Page 44 of 51
Assigning an IP address using the ipconfig command, or we can also assign an IP address with
the help of a command.
Page 45 of 51
Repeat the same procedure with other PCs to configure them thoroughly.
Page 46 of 51
[Link] Device Interface IPv4 Address Subnet mask
Then, configure the IP address in FastEthernet and serial ports according to IP addressing Table.
Page 47 of 51
Repeat the same procedure with other routers to configure them thoroughly.
Step 4: After configuring all of the devices we need to assign the routes to the routers.
To assign RIP routes to the particular router:
Router(config)#router rip
Router(config-router)#network [Link]
Router(config-router)#network [Link]
RIP Routes for Router1 are given below:
Router(config)#router rip
Router(config-router)#network [Link]
Page 48 of 51
Router(config-router)#network [Link]
Router(config-router)#network [Link]
RIP Routes for Router2 are given below:
Router(config)#router rip
Router(config-router)#network [Link]
Router(config-router)#network [Link]
As we can see in the below image we are getting replies which means the connection is working
properly.
Page 49 of 51
A simulation of the experiment is given below we are sending PDU from PC0 to PC2 and PC3 to
PC5
Page 50 of 51
Page 51 of 51