CS3591 CN Lab Manual R2021
CS3591 CN Lab Manual R2021
LAB MANUAL
Subject Code: CS3591
Subject Name: Computer Networks Lab
Program Name: B. E., CSE
Year & SEM: III & V
Regulation: 2021
Prepared By: S.Saravanakumar AP / CSE
PRACTICAL EXERCISES:
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.
Total Periods:30
EX.NO.1 learn to use commands like tcpdump, netstat, ipconfig, nslookup and traceroute.
Capture Ping and trace route PDUs using network
Protocol analyzer and examine
IFCONFIG – Used to view the TCP/IP configuration in Linux, UNIX and Macintosh
operating system
TRACERT / TRACEROUTE – Used in windows operating system to view the entire path a
packet travels from one device to other device
NSLOOKUP – Will look up the DNS Server to lookup the IP Address of any website.
Used for querying the name server for IP address of the given HOST.
Output 3:
Output 4: ping your current ip address also
Output 7: netstat
Output 8: color
Output 9: color 4
Output 10: color 7
RESULT:
AIM:
To Write a HTTP web client program to download a web page using TCP sockets.
ALGORITHM:
CLIENT SIDE:
2) Create a socket which binds the Ip address of server and the port address to acquire
Service.
4) Open a file and store the received data into the file.
SERVER SIDE:
3) Create a socket for the server socket which accepts the connection.
5) Download the content of the url received and send the data to client.
s = socket.socket (socket.AF_INET.socket.SOCK_STREAM)
s.connect((‘aurcc.com”,80))
s.sendall(b”GET/HTTP/I.I\r\nHost:www.aurcc.ac.in\r\nAccept:text/html\r\n\r\n”)
Print(str(s.recv(4096),’utf-8))
Program:
import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("shanmuganathanengg.in",80))
s.sendall(b"GET / HTTP/1.1\r\nHost:www.shanmuganathanengg.in\r\nAccept:text/html\r\n\r\n")
print(str(s.recv(4096),'utf-8'))
Output:
Viva Questions and Answers:
A socket is a software object that acts as an end point establishing a bidirectional network
2. Define HTTP.
HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by the World
Wide Web and this protocol defines how messages are formatted and transmitted, and what
actions Web servers and browsers should take in response to various commands.
4. Define webpage.
5. Define URL.
URL stands for Uniform Resource Locator, and is used to specify addresses on the World
Wide Web. A URL is the fundamental network identification for any resource connected to the
web (e.g., hypertext pages, images, and sound files). The protocol specifies how information
from the link is transferred.
RESULT:
The webpage is successfully downloaded and the contents are displayed and verified.
EX.NO.3 Implement Echo Client and Echo Server applications using TCP sockets in
python
The server will simply echo whatever it receives back to the client.
Aim:
To write a socket program for implementation of echo.
Algorithm:
Client Side:
Create a socket which binds the IP address of server and the port address to acquire service
Server Side:
Start the program
Create a socket for the server socket which accepts the connection
Echo Client:
import socket
import sys
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_address=('localhost',10000)
client.connect(server_address)
message=input()
print("sending ", message)
client.sendall(message.encode())
print("ORIGINAL: ",message)
data=client.recv(1000).decode()
print("ECHO: ",data)
client.close()
Echo Server:
import socket
import sys
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_address=('localhost',10000)
server.bind(server_address)
server.listen(1)
print('Waiting for a connection')
connection, client_address=server.accept()
print("Connection established with: ",client_address)
data=connection.recv(1000)
print("Received: ", data)
connection.sendall(data)
connection.close()
server.close()
Result:
Thus the program for simulation of echo server was written & executed
Output 1:
Output 2:
Ex: No: 3.2 Implement Chat application using TCP sockets in python
Aim:
To write a program to Simulation of DNS using UDP sockets.
Algorithm:
1. Start the program.
5.If your frames reach the server, it will send ACK signal to client otherwise it will
Program:
DNS Client:
import socket
hostname = socket.gethostname()
ipaddr = "127.0.0.1"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
addr = (ipaddr, 1234)
c = "Y"
while c.upper() == "Y":
req_domain = input("Enter domain name for which the IP is needed:")
send = s.sendto(req_domain.encode(), addr)
data, address = s.recvfrom(1024)
reply_ip = data.decode().strip()
print(f"The IP for the domain name {req_domain}:{reply_ip}")
c = (input("Continue? (y / n)"))
s.close()
DNS Server:
import socket
dns_table = {"www.google.com":"192.165.1.1",
"www.youtupe.com":"192.165.1.2",
"www.python.org":"192.165.1.3",
"www.amazon.in":"192.165.1.4",
"www.gmail.com":"192.165.1.5"}
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("Starting Server...")
s.bind(("127.0.0.1",1234))
while True:
data, address = s.recvfrom(1024)
print(f"{address}wants to fetch data!")
data = data.decode()
ip = dns_table.get(data, "Not Found!").encode()
send = s.sendto(ip,address)
s.close()
1.Define DNS.
DNS. (Domain Name System) The Internet's system for converting alphabetic names into
numeric IP addresses. For example, when a Web address (URL) is typed into a
browser, DNSservers return the IP address of the Web server associated with that name.
2.Define UDP.
User Datagram Protocol (UDP) is part of the Internet Protocol suite used by programs
running on
different computers on a network. UDP is used to send short messages called datagrams but
A MAC address is a hardware identification number that uniquely identifies each device on a
network.
An Internet Protocol address (IP address) is a numerical label assigned to each device
connected to
a computer network that uses the Internet Protocol for communication. An IP address serves
two
Class 1
A 1 – 126* 255.0.0.0
Output:
Server side: 1
Client Side: 1
Server Side: 2
Client Side: 2
Client Side: 3
RESULT:
Thus the above program a client-server application for chat using UDP was executed and
successfully
Ex.No.5 Simulation of ARP & RARP using TCP
AIM
To write a python program for simulating ARP & RARP protocols.
ALGORITHM
SERVER SIDE
CLIENT SIDE
Step1: Create a client socket and connect it to the server port number
Step2: Retrieve its own IP using built in function
Step3: send its address to the server
Step4: Close the input and output streams
Step5: Close the client socket
Server Program:
import socket
table={'192.168.1.1':'1E.4A.4A.11',
'192.168.2.1':'5E.51.4B.01',
'192.168.1.3':'4B.35.CD.32',
'192.168.4.1':'AF.4D.1F.FF',
'192.168.3.2':'C3.C5.EE.C2',
'1E.4A.4A.11':'192.168.1.1',
'5E.51.4B.01':'192.168.2.1',
'4B.35.CD.32':'192.168.1.3',
'AF.4D.1F.FF':'192.168.4.1',
'C3.C5.EE.C2':'192.168.3.2'}
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('',1234))
s.listen()
clientsocket,address = s.accept()
print("Connection from",address,"Has Estabilished")
ip=clientsocket.recv(1024)
ip=ip.decode("utf-8")
mac=table.get(ip,'No entry for given address')
clientsocket.send(mac.encode())
Client Program:
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('localhost',1234))
a=input("ARP or RARP:")
if(a=="ARP"):
add=input('Enter IP:')
elif(a=="RARP"):
add=input('Enter MAC:')
s.send(add.encode())
mac=s.recv(1024)
mac=mac.decode("utf-8")
if(a=="ARP"):
print('MAC of',add,'is:',mac)
else:
print('IP of',add,'is:',mac)
1.Define ARP.
The address resolution protocol (arp) is a protocol used by the Internet
Protocol (IP), specifically IPv4, to map IP network addresses to the
hardware addresses used by a data link protocol.
2.Define IPv4.
IPv4 (Internet Protocol Version 4) is the fourth revision of the Internet
Protocol (IP) used to to identify devices on a network through an addressing
system.
3.Define RARP.
RARP (Reverse Address Resolution Protocol) is a protocol by which a physical machine in a
local
area network can request to learn its IP address from a gateway server's Address Resolution
Protocol
(ARP) table .
Server: Output 1:
Client Output 1:
Client Output 2:
RESULT
Thus the implementation of ARP & RARP are done & executed successfully
Ex.No: 6 Study of Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS
AIM:
To Study Network simulator (NS).and Simulation of Congestion Control Algorithms
Using NS
Official Website
https://www.netacad.com/courses/packet-tracer
Packet loss
Packet loss occurs when one or more packets of data travelling across a computer network
fail to reach their destination. Packet loss is distinguished as one of the three main error types
encountered in digital communications; the other two being bit error and spurious packets
caused due to noise.
Packets can be lost in a network because they may be dropped when a queue in the network
node overflows. The amount of packet loss during the steady state is another important
property of a congestion control scheme. The larger the value of packet loss, the more
difficult it is for transport layer protocols to maintain high bandwidths, the sensitivity to loss
of individual packets, as well as to frequency and patterns of loss among longer packet
sequences is strongly dependent on the application itself.
Congestion control Algorithms
Slow-start is used in conjunction with other algorithms to avoid sending more data than the
network is capable of transmitting, that is, to avoid causing network congestion. The additive
increase/multiplicative decrease (AIMD) algorithm is a feedback control algorithm.
AIMD combines linear growth of the congestion window with an exponential reduction when
a congestion takes place. Multiple flows using AIMD congestion control will eventually
converge to use equal amounts of a contended link. Fast Retransmit is an enhancement to
TCP that reduces the time a sender waits before retransmitting a lost segment.
Ex.No: 7 Study of TCP/UDP performance using Simulation tool.
AIM:
To simulate the performance of TCP/UDP using Cisco Packet Tracer.
PRE LAB DISCUSSION:
TCP is reliable protocol. That is, the receiver always sends either positive or negative
Acknowledgement about the data packet to the sender, so that the sender always has
Bright clue about whether the data packet is reached the destination or it needs to
resend it.
TCP ensures that the data reaches intended destination in the same order it was sent.
TCP is connection oriented. TCP requires that connection between two remote points
be established before sending actual data.
TCP provides error-checking and recovery mechanism.
TCP provides end-to-end communication.
TCP provides flow control and quality of service.
TCP operates in Client/Server point-to-point mode.
TCP provides full duplex server, i.e. it can perform roles of both receiver and sender.
The User Datagram Protocol (UDP) is simplest Transport Layer communication
protocol available of the TCP/IP protocol suite. It involves minimum amount of
communication mechanism. UDP is said to be an unreliable transport protocol but it
uses IP services which provides best effort delivery mechanism.UDP is used when
acknowledgement of data does not hold any significance.
UDP is good protocol for data flowing in one direction.
UDP is simple and suitable for query based communications.
UDP is not connection oriented.
UDP does not provide congestion control mechanism.
UDP does not guarantee ordered delivery of data.
UDP is stateless.
UDP is suitable protocol for streaming applications such as VoIP, multimedia
streaming.
TCP Performance
Algorithm
1. Create a Simulator object.
2. Set routing as dynamic.
3. Open the trace and name trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the tcp agent.
8. Connect tcp and tcp sink.
9. Run the simulation.
UDP Performance
ALGORITHM :
1. Create a Simulator object.
2. Set routing as dynamic.
3. Open the trace and name trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the UDP agent.
8. Connect udp and null agents.
9. Run the simulation.
RESULT:
Thus the study of TCP/UDP performance is done successfully.
7 th Exercise Output:
Whenever you compose and send an email to another person, the message you send first
goes to a mail server. It’s the mail server which then sends the email when it is requested
from the email client (e.g. Gmail App) of the recipient’s device.
2.Configure IP addresses on the PCs, DNS Server and the Mail Server.
3. Now configure mail clients on the PCs and mail service on the generic server.
Mail Clients:
Click on PC0. Go to its Desktop tab, and click on Email. Configure the email client by
filling in the user, server and login information. Be sure to save.
PC0:
PC1:
Next, we’ll configure the email server.
To do this, click on the server, then click Services tab, pick email server from the menu.
Provide the Domain name of the server then click on Set to set it. In this example I’ve
used the name ‘mail.com’.
Proceed and add users and provide their passwords. I have two email clients (users) with
usernames ‘client1‘and ‘client2‘with a common password ‘adminkim‘
After entering a username and password, click on Add (+) to add the user to the server.
Lastly test the email service. Go to PC0 email client, compose an email and send it’s
to PC1 email address (client2@mail.com).
Try to see whether the email from PC0 is received on PC1. On the email client of PC1,
click on Receive.
Ex: No: 8 Simulation Distance Vector / Link State Routing Algorithm
Routing Information Protocol (RIP) is an active routing protocol that operates hop count as a routing
metric to find the most suitable route between the source and the destination network. It is a distance-
vector routing protocol that has an AD value of 120 and works on the Network layer of the OSI model.
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:
IP Addressing Table:
Then, create a network topology as shown below the image.
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.
Assigning an IP address using the ipconfig command, or we can also assign an IP address
with the help of a command.
Then, configure the IP address in FastEthernet and serial ports according to IP addressing
Table.
Step 4: After configuring all of the devices we need to assign the routes to the routers.
As we can see in the below image we are getting replies which means the connection is
working properly.
Result:
In order to investigate your issues further, we would like to run an analysis of the traffic
being sent between you and Salesforce. To do this, we will use the Wireshark application.
Wireshark is a tool that allows packet traces to be monitored, captured and analysed. Please
follow the steps below in order to obtain a capture of your network traffic using Wireshark.
Note: You will require some administrator rights on your machine in order to complete these
tests. If you are unsure, please contact your IT administrator.
Installing the Wireshark package
Visit the Wireshark download site, and download the appropriate Wireshark package or
installer for the operating system running on the system which is to be used for packet
capture.
When installing, ensure all components are selected for installation, including the optional
“Win cap” application.
Result:
AIM:
To implement error checking code using java.
ALGORITHM:
Start the Program
Given a bit string, append 0S to the end of it (the number of 0s is the same as the
degree of the generator polynomial) let B(x) be the polynomial corresponding to B.
Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and
determine the remainder R(x). This division is to be done using Modulo 2 Division.
Define T(x) = B(x) –R(x)
(T(x)/G(x) => remainder 0)
Transmit T, the bit string corresponding to T(x).
Let T’ represent the bit stream the receiver gets and T’(x) the associated polynomial.
The receiver divides T1(x) by G(x). If there is a 0 remainder, the receiver concludes T
= T’ and no error occurred otherwise, the receiver concludes an error occurred and
requires a retransmission
Stop the Program.
PROGRAM:
import java.io.*;
class crc_gen
{
public static void main(String args[]) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] data;
int[] div;
int[] divisor;
int[] rem;
int[] crc;
int data_bits, divisor_bits, tot_length;
System.out.println("Enter number of data bits : "); data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine()); divisor=new int[divisor_bits];
System.out.println("Enter Divisor bits : ");
for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());
System.out.print("Data bits are : ");
for(int i=0; i< data_bits; i++)
System.out.print(data[i]);
System.out.println();
System.out.print("divisor bits are : ");
for(int i=0; i< divisor_bits; i++)
System.out.print(divisor[i]);
System.out.println();
*/
tot_length=data_bits+divisor_bits-1;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
/* CRC GENERATION */
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print("Dividend (after appending 0's) are : "); for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();
for(int j=0; j<div.length; j++){
rem[j] = div[j];
}
rem=divide(div, divisor, rem);
for(int i=0;i<div.length;i++)
{
//append dividend and remainder
crc[i]=(div[i]^rem[i]);
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/* ERROR DETECTION */
System.out.println();
System.out.println("Enter CRC code of "+tot_length+" bits : "); for(int i=0; i<crc.length; i++)
crc[i]=Integer.parseInt(br.readLine());
System.out.print("crc bits are : ");
for(int i=0; i< crc.length; i++)
System.out.print(crc[i]);
System.out.println();
for(int j=0; j<crc.length; j++){
rem[j] = crc[j];
}
rem=divide(crc, divisor, rem);
for(int i=0; i< rem.length; i++)
{
if(rem[i]!=0)
{
System.out.println("Error");
break;
}
if(i==rem.length-1)
System.out.println("No Error");
}
System.out.println("THANK YOU. .....)");
}
static int[] divide(int div[],int divisor[], int rem[])
{
int cur=0;
while(true)
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
while(rem[cur]==0 && cur!=rem.length-1)
cur++;
if((rem.length-cur)<divisor.length)
break;
}
return rem;
}
}
OUTPUT :
Enter number of data bits :
7
Enter data bits :
1
0
1
1
0
0
1
Enter number of bits in divisor :
3
Enter Divisor bits :
1
0
1
Dividend (after appending 0's) are : 101100100
CRC code :
101100111
Enter CRC code of 9 bits :
1
0
1
1
0
0
1
0
1
crc bits are : 101100101
RESULT:
Thus the above program for error checking code using was executed successfully.