Submitted By: Roll No Course Brance Section Year Semester: Page 1 of 50
Submitted By: Roll No Course Brance Section Year Semester: Page 1 of 50
TEL: (0120)-2965554
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
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 50
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 50
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 50
Page 4 of 50
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.
ipconfig /release Releases the current IP address from the network adapter.
ipconfig /registerdns Refreshes all DHCP leases and re-registers DNS names.
🔹 Usage Examples
Check your IP address
ipconfig
ipconfig /all
Fix connectivity issues (renew IP)
ipconfig /release
ipconfig /renew
ipconfig /flushdns
Page 5 of 50
2. PING Command:
Here are the commonly used ping commands in Windows OS, used to test network
connectivity and diagnose issues:
🔹 Example:
ping [Link]
ping [Link]
ping -l <size> <host> Sends a ping packet of a specific byte size (default is 32 bytes).
ping -4 <host> Forces the use of IPv4.
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.
Page 6 of 50
📌 Basic Tracert Command
Command Description
tracert <hostname or IP> Traces the route taken by packets to reach a destination.
🔹 Example:
tracert [Link]
tracert -w <timeout> <host> Set timeout in milliseconds to wait for each reply.
🛠️ Use Case
● Helps identify where in the network chain a slowdown or disconnection is occurring.
● Useful for diagnosing ISP or DNS issues.
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.
🔹 Example:
nslookup [Link]
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:
● Physical (MAC) address
Page 8 of 50
● Transport name (interface info)
Command Description
Shows verbose output: includes connection name, network adapter
getmac /v
name, and MAC address.
🔍 Examples
1. Show MAC addresses (default format)
2. getmac
3. Detailed info (adapter name + MAC)
4. getmac /v
5. List format output
6. getmac /fo list
7. CSV format without headers
8. getmac /fo csv /nh
🧠 Tip:
You can also view MAC addresses using:
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
Page 9 of 50
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).
After using:
netstat -ano
You can match the PID (last column) with the program name:
tasklist /fi "PID eq 1234"
Page 10 of 50
[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:
● Useful in network troubleshooting or identifying machines in a domain or LAN.
● Often used along with commands like ping, ipconfig, or net view.
🔧 GUI Method:
following:
Page 11 of 50
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
arp -a Displays all ARP entries in the ARP table.
📌 Example Usage:
🔍 View ARP table:
arp -a
Output:
Interface: [Link] --- 0x10
Internet Address Physical Address Type
[Link] 00-1d-7e-a4-b3-22 dynamic
🔒 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 12 of 50
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 13 of 50
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
route print Displays the current routing table.
🛠️ Examples:
View Routing Table
route print
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 14 of 50
Page 15 of 50
📘 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
echo Displays text or turns echoing on/off
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 16 of 50
🔹 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
Copy copy [Link] backup\[Link]
🔹 Useful Tips
● Always use @echo off at the top to make output clean.
● %~dp0 gives the directory of the batch file.
● Use double % (e.g., %%i) in loops when writing in batch files (single % for CMD
directly).
Page 17 of 50
2. Save as [Link].
3. Double-click to execute or run from CMD.
Page 18 of 50
Q1: Write a program in batch to perform all arithmetic
operations:
Page 19 of 50
Q2: Write a program in batch to perform all arithmetic
operations through function:
Page 20 of 50
Page 21 of 50
Q3: Write a program to perform sum and multiplication of series
from 1 to N by using Function:
Page 22 of 50
Q3: Write a program to find factorial of given number?
OUTPUT:
Page 23 of 50
Q4: Write a program to print table of given number;
OUTPUT:
Page 24 of 50
Q5: Write a program to print pattern:
OUTPUT:
Page 25 of 50
Q6: Write a program to print pattern second.
OUTPUT:
Page 26 of 50
Q7: Write a program to print pattern third
OUTPUT:
Page 27 of 50
Page 28 of 50
CLIENT/SERVER ARCHITECTURE:
Page 29 of 50
Client/Server Socket Connection Diagram:
Page 30 of 50
TCP PROGRAMMING IN JAVA:
// [Link]
import [Link].*;
import [Link].*;
[Link]();
} catch (Exception e) {
[Link](e);
}
}
}
// [Link]
import [Link].*;
import [Link].*;
Page 31 of 50
📘 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 50
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
Protocol UDP (connectionless)
⚠️ Important Tips:
● Use try-catch for better error handling.
● Use setSoTimeout() for receive timeout.
● Avoid using UDP for critical data transfers (use TCP instead).
Page 33 of 50
Page 34 of 50
NETWORKING TOOLS:
1. CRIMPLING TOOL:
Page 35 of 50
3.RJ45 Connector:
Page 36 of 50
DIFFERENCE BETWEEN STRAIGHT AND CROSSOVER
CABLE:
Here's a clear comparison between Straight Through Cable and Crossover Cable, used in
computer networking:
🧠 Automatic Crossover No
Needed?
📥 Pin Mapping Pin 1 → Pin 1, Pin 2 → Pin 2, etc.
🔁 2. Crossover Cable
Feature Description
🔧 Purpose Connects similar devices
Page 37 of 50
🧠 Summary Table:
Feature Straight Cable Crossover Cable
Device Type Different devices Similar devices
💡 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 50
Page 39 of 50
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
Device-Type Selection Box Select routers, switches, PCs, etc.
📦 Steps:
1. Add 2 PCs: Click End Devices → PC, then place on the workspace.
Page 40 of 50
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]
Shows status of
show ip interface brief
interfaces
Page 41 of 50
🎥 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 50
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 50
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 50
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 50
Repeat the same procedure with other PCs to configure them thoroughly.
Page 46 of 50
[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 50
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 50
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 50
A simulation of the experiment is given below we are sending PDU from PC0 to PC2 and
PC3 to PC5
Page 50 of 50