Lab Manual
Lab Manual
II Year / IV Semester
Lab Manual
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture
ping and trace route PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets.
3. Applications using TCP sockets like: a) Echo client and echo server b) Chat
5. Use a tool like Wireshark to capture packets and examine the packets
7. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using
NS.
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
EX No.:1
Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and trace route PDUs using a network protocol analyzer and examine.
AIM:
THEORY:
Network diagnostic commands are essential tools for analyzing and troubleshooting
network connectivity and performance.
tcpdump: A command-line packet analyzer used to capture network packets and
display them in real-time.
netstat: Displays network connections, routing tables, and interface statistics.
ifconfig: Displays or configures a network interface on UNIX/Linux systems.
nslookup: Queries DNS to obtain domain name or IP address mapping.
traceroute: Displays the route packets take to reach a specified network host.
PROCEDURE:
1. tcpdump:
o Open terminal.
2. netstat:
o Open terminal.
3. ifconfig:
o Open terminal.
4. nslookup:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
o Open terminal.
5. traceroute:
o Open terminal.
o Open Wireshark.
OUTPUT:
RESULT:
Viva Questions:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
EX No.:2
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
Write a HTTP web client program to download a web page using TCP sockets
AIM:
To write an HTTP client program to download a web page using TCP sockets.
ALGORITHM:
2. Define the web server and port (default HTTP port: 80).
PROGRAM:
import socket
host = "example.com"
port = 80
# Create a socket
client_socket.connect((host, port))
client_socket.send(request.encode())
data = client_socket.recv(4096)
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
print(data.decode())
client_socket.close()
OUTPUT:
HTTP/1.1 200 OK
...
<html>
<head><title>Example Domain</title></head>
<body>...</body>
</html>
RESULT:
The HTTP client program was successfully executed to retrieve a web page using TCP
sockets.
This Python program is an HTTP client that connects to a web server using TCP sockets to
fetch a web page.
o host = "example.com" → Specifies the web server (you can replace this with
any other website).
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
GET / HTTP/1.1
Host: example.com
o data = client_socket.recv(4096)
o The client waits for the server's response, which contains the HTTP headers
and HTML content of the webpage.
o print(data.decode())
o client_socket.close()
HTTP/1.1 200 OK
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
<html>
<head><title>Example Domain</title></head>
<body>...</body>
</html>
EX.No.:3 Applications using TCP sockets like: a) Echo client and echo server b) Chat
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
ALGORITHM:
SERVER PROGRAM:
import socket
server_socket.bind(("localhost", 12345))
server_socket.listen(1)
print("Server is listening...")
data = conn.recv(1024)
print("Received:", data.decode())
conn.close()
server_socket.close()
Client Program:
import socket
client_socket.connect(("localhost", 12345))
client_socket.send(message.encode())
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
data = client_socket.recv(1024)
client_socket.close()
Output:
Server is listening...
ALGORITHM:
SERVER PROGRAM:
import socket
server_socket.bind(("localhost", 12346))
server_socket.listen(1)
print(f"Connected to {addr}")
while True:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
data = conn.recv(1024).decode()
break
print("Client:", data)
conn.send(reply.encode())
if reply.lower() == "bye":
print("Chat ended.")
break
conn.close()
server_socket.close()
Client Program:
import socket
client_socket.connect(("localhost", 12346))
while True:
client_socket.send(message.encode())
if message.lower() == "bye":
print("Chat ended.")
break
data = client_socket.recv(1024).decode()
break
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
print("Server:", data)
client_socket.close()
Output:
Client: Hi there!
You: Hello!
Client: bye
Result:
The Echo Client-Server model and chat application was successfully implemented using TCP
sockets.
Explanation
The Echo Server receives a message from the client and sends the same message back.
How it Works:
1. Server:
2. Client:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
This is a two-way communication program where both client and server can send and
receive messages.
How it Works:
1. Server:
o Binds it to localhost:12346.
2. Client:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
Echo Server → Sends back the same message received from the client.
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
AIM:
To simulate the working of DNS using UDP sockets in Cisco Packet Tracer and understand
how hostname resolution occurs.
ALGORITHM:
1. PC sends a UDP packet to the DNS server at port 53 with a domain name query.
THEORY:
A DNS client sends a query to the DNS server, which replies with the IP.
DEVICES NEEDED:
1 Server (Server0)
1 Switch
CONNECTIVITY DIAGRAM:
[PC0]------|
[Switch]------[Server]
[PC1]------|
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
1. Network Setup
o 1 Switch
2. IP Configuration
o PC0:
IP:192.168.1.10
Subnet:255.255.255.0 (Same for all below devices)
DNS: 192.168.1.100
o PC1:
IP:192.168.1.11
DNS: 192.168.1.100
o Server:
IP:192.168.1.100
DNS: 192.168.1.100
o Turn DNS ON
Name: www.google.com
Address: 192.168.1.100
o It should open a page hosted on PC1 (if it's running a web service).
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
SIMULATION SCREENS:
Setup
Output
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
EX. NO. 5 Use a tool like Wireshark to capture packets and examine the packets
AIM
To understand how network protocols work by capturing and analyzing packets using
Wireshark, a network protocol analyzer.
ALGORITHM:
1. Start Wireshark.
8. Interpret protocol layers: Ethernet, IP, TCP/UDP, Application (HTTP, DNS, etc.).
PROCEDURE (STEP-BY-STEP):
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
Output Screens
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
Viva Questions:
1. What is Wireshark?
2. What is packet capturing?
3. Why do we need a tool like Wireshark?
4. What is a .pcap or .pcapng file?
5. What are the basic layers you observe when analyzing a packet?
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
AIM
To learn how IP addresses are mapped to MAC addresses and vice versa.
THEORY:
ARP is a network layer protocol used to convert an IP address into a physical MAC address.
When a device wants to communicate with another device on the same network, it uses
ARP to find out the MAC address associated with the destination IP address.
ALGORITHM:
ARP Simulation:
RARP Simulation:
PROGRAM CODE:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# ARP/RARP Simulation
arp_table = {
'192.168.1.1': '00:14:22:01:23:45',
'192.168.1.2': '00:14:22:01:23:46',
'192.168.1.3': '00:14:22:01:23:47'
# ARP Simulation
def arp(ip):
if ip in arp_table:
else:
# RARP Simulation
def rarp(mac):
if mac in rarp_table:
else:
# Main Function
if __name__ == '__main__':
if choice == 1:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
arp(ip)
elif choice == 2:
rarp(mac)
else:
print("Invalid Choice")
o A dictionary arp_table is created where keys are IP addresses, and values are
their corresponding MAC addresses.
3. ARP Function:
o The arp() function accepts an IP address as input and checks if the IP exists in
the arp_table.
4. RARP Function:
o The rarp() function accepts a MAC address as input and checks if the MAC
address exists in the rarp_table.
o If not, it notifies the user that the MAC address is not found.
5. Main Function:
Output:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
RESULT:
The ARP and RARP protocols were successfully simulated using Python.
Viva Questions:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
EX. NO. 7
Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using
NS.
AIM:
THEORY:
Network Simulator (NS): Network Simulator (NS) is a discrete event simulator targeted
primarily for networking research. It provides support for simulation of TCP, routing, and
multicast protocols over wired and wireless networks.
Congestion Control Algorithms: Congestion control algorithms are used to prevent network
congestion by managing the amount of data that can be transmitted. Common congestion
control algorithms include:
TCP Tahoe
TCP Reno
ALGORITHM:
Simulation Steps:
3. Set up nodes and links with necessary parameters such as bandwidth and delay.
4. Configure TCP or UDP traffic agents between source and destination nodes.
PROGRAM CODE (SAMPLE TCL SCRIPT FOR TCP CONGESTION CONTROL SIMULATION):
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# Create Nodes
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# Schedule Events
proc finish {} {
$ns flush-trace
close $tracefile
close $namfile
exit 0
# Run Simulation
$ns run
OUTPUT:
3. The NAM file provides a graphical representation of the network and packet flow.
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
RESULT:
The simulation of congestion control algorithms was successfully executed using NS, and the
network performance was analyzed.
Viva Questions:
2. How does the Leaky Bucket algorithm differ from the Token Bucket algorithm?
EX. NO. 8
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
AIM:
THEORY:
ALGORITHM:
2. Define the network topology using TCL (Tool Command Language) script.
3. Create nodes and establish links with specified bandwidth and delay.
5. Generate traffic using FTP for TCP and CBR (Constant Bit Rate) for UDP.
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# Create Nodes
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# Schedule Events
proc finish {} {
$ns flush-trace
close $tracefile
close $namfile
exit 0
# Run Simulation
$ns run
OUTPUT:
1. The simulation will generate trace files containing packet transmission details.
2. The NAM file will visually display the network topology and data flow.
3. Performance metrics such as throughput and delay can be derived from the trace
files.
RESULT:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
The TCP and UDP performance was successfully simulated and analyzed using a network
simulation tool.
Viva Questions:
1. Simulator Initialization:
o The simulator logs events to trace files and NAM files, which help visualize
the simulation.
3. Node Creation:
o Two nodes, n0 and n1, are created to simulate the sender and receiver.
4. Link Setup:
o A duplex link with 1Mbps bandwidth and 10ms delay is established between
the nodes using the DropTail queue management.
o A TCP agent is attached to node n0, and a TCP sink agent is attached to node
n1.
o A UDP agent is attached to node n0, and a Null agent (used to discard
packets) is attached to node n1.
o A CBR traffic generator is configured to send data over the UDP connection.
7. Event Scheduling:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
8. Finish Procedure:
o The finish procedure flushes trace files, closes them, and launches the NAM
visualization tool.
9. Simulation Execution:
EX. NO. 9
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
AIM:
To understand the working principles of Distance Vector and Link State Routing
algorithms.
To simulate Distance Vector and Link State Routing algorithms using a network
simulation tool.
THEORY:
Distance Vector Routing is a dynamic routing algorithm in which each router maintains a
table containing the distance to every other router in the network. The table is updated by
exchanging information with neighboring routers periodically.
Link State Routing is a dynamic routing algorithm in which each router maintains information
about the entire topology of the network. Each router independently computes the shortest
path to every other router using Dijkstra's algorithm.
ALGORITHM:
PROGRAM CODE (SAMPLE TCL SCRIPT FOR DISTANCE VECTOR ROUTING SIMULATION):
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# Create Nodes
# Define Links
$ns rtproto DV
proc finish {} {
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
$ns flush-trace
close $tracefile
close $namfile
exit 0
# Run Simulation
$ns run
1. Simulator Initialization:
o The simulation generates trace and NAM files for analysis and visualization.
3. Node Creation:
4. Link Setup:
o Duplex links with specified bandwidth and delay are set between the nodes.
o The Distance Vector routing protocol is set using $ns rtproto DV.
6. Simulation Events:
7. Finish Procedure:
o The finish procedure closes trace files and launches the NAM visualization
tool.
OUTPUT:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
1. The simulation will generate trace files with routing updates and data transmission
details.
2. The NAM file will display the network topology and packet flows.
3. Convergence time and route paths can be analyzed from the trace file.
RESULT:
The simulation of Distance Vector and Link State Routing algorithms was successfully
executed, and the performance was analyzed.
Viva Questions:
1. What is the difference between Distance Vector and Link State Routing?
3. What are the advantages of Link State Routing over Distance Vector Routing?
EX. NO. 10
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
AIM:
THEORY:
Working Principle:
2. The remainder of this division is appended to the original data as the CRC checksum.
ALGORITHM:
2. Append zero bits (equal to the degree of the divisor) to the data.
result = []
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
return ''.join(result)
pick = len(divisor)
tmp = dividend[:pick]
if tmp[0] == '1':
else:
pick += 1
if tmp[0] == '1':
else:
return tmp
l_key = len(divisor)
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
# Example
data = "101010"
divisor = "1101"
# Encode data
1. XOR Function:
2. Modulo-2 Division:
o The mod2div() function performs binary division using XOR and returns the
remainder.
3. Encoding Function:
o The encodeData() function appends zero bits to the data and calculates the
CRC checksum using modulo-2 division.
4. Output:
o The input data, divisor, and encoded data with CRC are printed.
OUTPUT:
Divisor: 1101
RESULT:
CS3591_COMPUTER NETWORKS
4931_Grace College of Engineering, Thoothukudi
The CRC error correction code was successfully simulated and verified using Python.
Viva Questions:
CS3591_COMPUTER NETWORKS