V Cse Cs3591 CN Labmanual 1
V Cse Cs3591 CN Labmanual 1
Capture ping and trace route PDUs using a network protocol analyzer and examine
Aim:
To use commands like tcpdump, netstat, ifconfig, nslookup and trace route. Capture ping
and trace route PDUs using a network protocol analyzer and examine.
1. Tcpdump
Tcpdump is a command line utility that allows you to capture and analyze network traffic
going through your system.
Procedure
$ which tcpdump
/usr/sbin/tcpdump
$ su
$ sudo –i to change #
($ is changed to # and the commands can be executed in supervisor)
Use the command tcpdump -D to see which interfaces are available for capture.
4. enp2s0
5. usbmon2 (USB bus number 2)
5 packets captured
5 packets captured
Filtering packets
To filter packets based on protocol, specifying the protocol in the command line. For example, capture
ICMP packets only by using this command:
5 packets captured
$ ping opensource.com
2. netstat
netstat (network statistics) is a command line tool for monitoring network connections both
incoming and outgoing as well as viewing routing tables, interface statistics etc.
3. ifconfig
It displays the details of a network interface card like IP address, MAC Address, and the status of a
network interface card
nslookup (stands for “Name Server Lookup”) is a useful command for getting information from
DNS server. It is a network administration tool for querying the Domain Name System (DNS) to obtain
domain name or IP address mapping or any other specific DNS record.
Non-authoritative answer:
Name: annauniv.edu
Address: 103.70.60.38
Server: 8.8.8.8
Address: 8.8 8.8#53
Non-authoritative answer:
Non-authoritative answer:
Name: annauniv.edu
Address: 103.70.60.38
annauniv.edu text = "v=spf1 ip4:103.70.60.40 -all"
origin = ns.annauniv.edu
mail addr = root.annauniv.edu
serial = 20170907
refresh = 300
retry = 900
expire = 604800
minimum = 86400
annauniv.edu nameserver = ns.annauniv.edu.
Server: 8.8.8.8
Address: 8.8 8.8#53
Non-authoritative answer:
5. traceroute
The traceroute command is used in Linux to map the journey that a packet of information
undertakes from its source to its destination.
Usage:
Options:
-4 Use IPv4
-6 Use IPv6
Capture ping and traceroute PDUs using a network protocol analyzer and examine.
Wireshark is free & Open source network packet analyzer that is used for network
analysis, troubleshooting, etc.
Wireshark is quite similar to tcpdump, the major difference between the two is that Wireshark has
a graphical interface with built-in filtering options, which make it easy to use.
To Open Wireshark
# sudo wireshark
In a konsole execute
# ping www.sudo.com
# traceroute www.google.com
Result:
Thus commands like tcpdump, netstat, ifconfig, nslookup and traceroute was used. Ping
and traceroute PDUs using a network protocol analyzer was captured and examined.
Ex.No.2 Write a HTTP web client program to download a web page using TCP sockets
Aim:
To write a program in java to create a HTTP web client program to download a web
page using TCP sockets.
Algorithm:
3. To download an image, use java URL class which can be found under java.net package.
4. The file is downloaded from server and is stored in the current working directory.
Program
Download.java
import java.io.*;
import java.net.URL;
try
int length = 0;
{
System.out.println("Buffer Read of length: " +
length); outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
catch(Exception e)
Output
F:\Abarna\Lab>javac Download.java
Thus created a program in java for a HTTP web client program to download a web page
using TCP sockets is written and executed successfully.
Ex.No.3a APPLICATION USING TCP SOCKETS - ECHO CLIENT AND ECHO SERVER
Aim:
Algorithm
2. In Server
b) Listen for new connection and when a connection arrives, accept it.
g) Stop.
3. In Client
f) Stop.
Program
Server.java
import java.net.*;
import java.lang.*;
import java.io.*;
{
public static final int PORT = 4000;
try
try
sock = sersock.accept();
System.out.println(ins.readLine());
sock.close();
catch(SocketException se)
catch(Exception e)
}
CS3591_CN
}
Client.java
import java.lang.*;
import java.io.*;
import java.net.*;
import java.net.InetAddress;
class client
Socket sock=null;
DataInputStream dis=null;
PrintStream ps=null;
try
{
sock= new Socket(InetAddress.getLocalHost(),Server.PORT);
ps= new PrintStream(sock.getOutputStream()); ps.println(" Hi
from client");
catch(SocketException e)
catch(IOException e)
}
finally
{
try
sock.close();
catch(IOException ie)
Output
In server window:
Hi from client
In client window:
Trying to connect
Thus a program in Java implemented an applications using TCP Sockets like echo
client and echo server
i
Aim
2. In Server
b) Listen for new connection and when a connection arrives, accept it.
h) Stop
3. In Client
g) Stop
Program
tcpchatserver.java
import java.io.*;
import java.net.*;
class tcpchatserver
{
public static void main(String args[])throws
Exception {
PrintWriter toClient;
try
System.out.print("\nServer started\n");
System.out.println("Client connected");
OutputStreamWriter(Clt.getOutputStream())), true);
while(true)
CltMsg= fromClient.readLine();
if( ltMsg.equals("end"))
break;
else
SrvMsg = fromUser.readLine();
toClient.println(SrvMsg);
System.out.println("\nClient Disconnected");
fromClient.close();
toClient.close();
fromUser.close();
Clt.close();
Srv.close();
catch (Exception E)
System.out.println(E.getMessage());
tcpchatclient.java
import java.io.*;
import java.net.*;
class tcpchatclient
Socket Clt;
PrintWriter toServer;
try
OutputStreamWriter(Clt.getOutputStream())), true);
while (true)
if (CltMsg.equals("end"))
break;
SrvMsg = fromServer.readLine();
catch(Exception E)
System.out.println(E.getMessage());
Output
In server window:
Server started
Client connected
Server : hai
Client Disconnected
In client window:
Client : hello
Result:
Thus a program in Java implemented an application using TCP Sockets like chat.
Ex.No.4 SIMULATION OF DNS USING UDP SOCKETS
Aim :
To write a program in Java to perform Simulation of DNS using UDP sockets.
Algorithm
2. In Server
j) Stop
3. In Client
h) Stop
Program
dnsclient.java
import java.io.*;
import java.net.*;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
senddata = sentence.getBytes();
receivedata.length);
clientsocket.receive(recvpack);
clientsocket.close();
dnsserver.java
import java.io.*;
import java.net.*;
str = str.trim();
if (array[i].equals(str))
return i;
return -1;
GRACESystem.out.println("PressCtrl+toQuit");
while (true)
String capsent;
else
capsent = "Host Not Found";
i
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
Output
In server window
In client window
IP Address: 68.180.206.184
Result :
Aim :
To implement the code to capture packets and examine the packets using
wireshark.
Procedure:
1. A network packet analyzer will try to capture network packets and tries to display that packet data
as detailed as possible.
Program :
import sys
Output:
###[ Ethernet ]###
dst = 00:11:22:33:44:55
src = 66:77:88:99:00:11
ihl = 5
tos = 0x0
len = 1500
id = 52786
flags = DF
frag = 0
ttl = 128
proto= tcp
chksum= 0xe877
src = 192.168.1.10
dst = 216.58.194.78
\options \ ###[ TCP ]###
sport = 54321
dport= http
seq = 3665840854
ack = 2542707921
dataofs = 5
reserved = 0
flags = FA
window= 8760
chksum= 0x9d6c
urgptr= 0
options = [('MSS', 1460), ('SAckOK', ''), ('Timestamp', (12576855, 2413)), ('NOP', None),
('WScale', 7)] ###[ Raw ]###
load = ''
Result:
Thus the program was executed successfully using tool Wireshark to capture packet and
examine the packet.
Ex.No.6a SIMULATION OF ARP PROTOCOLS
Aim:
Algorithm:
2. In Client
a. Start the program
3. In Server
a. Start the program
c. Server maintains the table in which IP and corresponding MAC addresses are stored.
Program
Clientarp.java
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
try
dout.writeBytes(str1+'\n');
String str=din.readLine();
clsct.close();
catch (Exception e)
System.out.println(e);
Serverarp.java
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
try
Socket obj1=obj.accept();
while(true)
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
if(str.equals(ip[i]))
dout.writeBytes(mac[i]+'\n');
break;
obj.close();
catch(Exception e)
System.out.println(e);
Output
27
Ex.No.6b SIMULATION OF RARP PROTOCOLS
Aim:
Algorithm:
2. In Client
3. In Server
e. Map the MAC address with its MAC address and return the IP address to client.
Program
clientrarp.java
import java.io.*;
import java.net.*;
import java.util.*;
try {
DatagramSocket client = new DatagramSocket();
InetAddress addr = InetAddress.getByName("127.0.0.1");
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1024];
sendByte = str.getBytes();
catch(Exception e) {
System.out.println(e);
}}}
serverrarp.java
import java.io.*;
import java.net.*;
import java.util.*;
try
String s = str.trim();
if(s.equals(mac[i]))
sendByte = ip[i].getBytes();
break;
break;
}catch(Exception e)
System.out.println(e);
Output:
AIM:
INTRODUCTION :
Network Simulator (Version 2), widely known as NS2, is simply an eventdriven simulation tool
that has proved useful in studying the dynamic nature of communication networks. Simulation of wired as
well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP) can be done using
NS2. In general, NS2 provides users with a way of specifying such network protocols and simulating their
corresponding behaviors. Due to its flexibility and modular nature, NS2 has gained constant popularity in
the networking research community since its birth in 1989. Ever since, several revolutions and revisions
have marked the growing maturity of the tool, thanks to substantial contributions from the players in the
field. Among these are the University of California and Cornell University who developed the REAL
network simulator, 1 the foundation which NS is based on.
Since 1995 the Defense Advanced Research Projects Agency (DARPA) supported development of
NS through the Virtual InterNetwork Testbed (VINT) project currently the National Science Foundation
(NSF) has joined the ride in development. Last but not the least, the group of Researchers and developers
in the community are constantly working to keep NS2 strong and versatile.
BASIC ARCHITECTURE :
Figure shows the basic architecture of NS2. NS2 provides users with executable command ns which
take on input argument, the name of a Tcl simulation scripting file. Users are feeding the name of a Tcl
simulation script (which sets up a simulation) as an input argument of an NS2 executable command ns.
In most cases, a simulation trace file is created, and is used to plot graph and/or to create animation.
NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl). While the
C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the
OTcl sets up simulation by assembling and configuring the objects as well as scheduling discrete events
(i.e., a frontend).
The C++ and the OTcl are linked together using TclCL. Mapped to a C++ object, variables in the
OTcl domains are sometimes referred to as handles. Conceptually, a handle (e.g., n as a Node handle) is
just a string (e.g., _o10) in the OTcl domain, and does not contain any functionality.
Instead, the functionality (e.g., receiving a packet) is defined in the mapped C++ object (e.g., of class
Connector). In the OTcl domain, a handle acts as a frontend which interacts with users and other OTcl
objects. It may define its own procedures and variables to facilitate the interaction. Note that the member
procedures and variables in the OTcl domain are called instance procedures (instprocs) and instance
variables (instvars), respectively. Before proceeding further, the readers are encouraged to learn C++ and
OTcl languages.
NS2 provides a large number of built-in C++ objects. It is advisable to use these C++ objects to set
up a simulation using a Tcl simulation script. However, advance users may find these objects insufficient.
They need to develop their own C++ objects, and use a Tcl configuration interface to put together these
objects. After simulation, NS2 outputs either text-based or animation-based simulation results. To interpret
these results graphically and interactively, tools such as NAM (Network AniMator) and XGraph are used.
To analyze a particular behavior of the network, users can extract a relevant subset of text-based data and
transform it to a more conceivable presentation.
CONCEPT OVERVIEW
ns uses two languages because simulator has two different kinds of things it needs to do. On one
hand, detailed simulations of protocols require a systems programming language which can efficiently
manipulate bytes, packet headers and implement algorithms that run over large data sets. For these tasks
run-time speed is important and turn-around time (run simulation, find bug, fix bug, recompile, re-run) is
less important. On the other hand, a large part of network research involves slightly varying parameters or
configurations, or quickly exploring number of scenarios.
In these cases, iteration time (change the model and re-run) is more important. Since configuration
runs once (at the beginning of the simulation), run-time of this part of the task is less important. ns meets
both of these needs with two languages, C++ and OTcl.
Link failures
Post-Processing Procedures
proc finish {}
global ns nf
$ns flush-trace
close $nf
exit 0
}
Schedule Events
Call ‘finish’
$ns run
RESULT:
Aim:
a. Queuetype : Droptail
d. Queue size: 10
d. Click done
8. Click TCL and specify the window side of the sliding window and the transfer of packets and
save the file as sliding.tcl in C:\cygwin\Your folder
Program:
#===================================
# Simulation parameters setup
#===================================
set val(stop) 5.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 2 nodes
#===================================
# Links Definition
#===================================
#Createlinks between nodes
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection set ftp0
[new Application/FTP]
$ftp0 attach-agent $tcp1
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
$ns flush-trace
close $tracefile
close $namfile
exit 0
$ns run
Steps to execute:
1. Run cygwin and change the directory
$ cd ..
admin@CS03C037 /home
$ cd ..
Admin@CS03C037/
$ ls
Cygwin.bat Cygwin.ico Abarna bin cygdrive dev etc home lib opt proc tmp usr var
admin@CS03C037 /
$ cd Abarna
admin@CS03C037 /Abarna
$ ls
sliding.tcl
admin@CS03C037 /Abarna
$ ns sliding.tcl
admin@CS03C037 /Abarna
admin@CS03C037 /Abarna
$ ns sliding.tcl
🡪
ii. In File Open select sliding.nam from C:\cygwin\Your folder
Result:
Thus performed simulation of Congestion Control Algorithms (sliding window) using NS.
Ex.No:8 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL
Aim :
Algorithm
2. The duplex links between n0 and n2, and n1 and n2 have 2 Mbps of bandwidth and 10
ms of delay.
3. The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of delay.
4. Each node uses a DropTail queue, of which the maximum size is 10.
5. A "tcp" agent is attached to n0, and a connection is established to a tcp "sink" agent
attached to n3.
6. As default, the maximum size of a packet that a "tcp" agent can generate is 1KByte.
7. A tcp "sink" agent generates and sends A K packets to the sender (tcp agent) and frees
the received packets.
10. A "ftp" and a "cbr" traffic generator are attached to "tcp" and "udp" agents respectively,
and the "cbr" is configured to generate 1 KByte packets at the rate of 1 Mbps.
11. The "cbr" is set to start at 0.1 sec and stop at 4.5 sec, and "ftp" is set to start at 1.0 sec and
stop at 4.0 sec
Program
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
$ns run
Output
Result:
Aim:
ALGORITHM:
3. Open a nam trace file and define finish procedure then close the trace file, and execute
nam on trace file.
9. Choose distance vector routing protocol to transmit data from sender to receiver.
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exit 0
}
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns at 45 "finish"
$ns run
Output
Result:
Aim:
Algorithm:
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on trace file.
9. Choose Link state routing protocol to transmit data from sender to receiver.
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
$ns at 45 "finish"
$ns run
Output:
Result:
Aim :
(CRC)
Algorithm :
At sender side
2. Read the number of bits to be sent. Let n be the Number of bits in data to be sent from
sender side.
3. Read the number of bits in the divisor. Let k be the Number of bits in the divisor (key
obtained from generator polynomial).
4. The binary data is first increased by adding k-1 zeros in the end of the data
5. Use modulo-2 binary division to divide binary data by the divisor and store remainder of
division.
6. Append the remainder at the end of the data to form the encoded data and send the
same
At receiver side
1. Perform modulo-2 division again and if remainder is 0, then there are no errors.
Modulo 2 division
In each step, a copy of the divisor (or data) is XORed with the k bits of the dividend.
The result of the XOR operation (remainder) is (n-1) bits, which is used for the next step
after 1 extra bit is pulled down to make it n bits long.
When there are no bits left to pull down, we have a result. The (n-1)-bit remainder
which is appended at the sender side.
Program
import java.io.*;
import java.util.*;
class crc
{
int n;
// Read input
n = input.nextInt();
//Read Divisor
n = input.nextInt();
//Perform Division
System.out.print(remainder[i]);
{
System.out.print(data[i]);
System.out.print(remainder[i]);
System.out.println();
receive(sent_data, divisor);
int remainder[] , i;
+ remainder[0]);
System.out.print("Remainder : ");
// If first bit of remainder is 1 then exor the remainder bits with divisor bits
if(remainder[0] == 1)
{
for(int j=1 ; j < divisor.length ; j++)
System.out.print(remainder[j-1]);
else
remainder[divisor.length- 1] = data[i+divisor.length];
System.out.println(remainder[divisor.length-1]);
return remainder;
if(a == b)
return 0;
return 1;
{
if(remainder[i] != 0)
Output
D:\Abarna>javac crc.java
D:\Abarna>java crc
0
Enter bit number 2:
Remainder : 0101
Remainder : 1010
Remainder : 0011
Remainder : 0110
Remainder : 1100
Remainder : 1110
Remainder : 1010
101
1001101101
1
Enter bit number 6:
0
Enter bit number 4:
Remainder : 0101
Remainder : 1010
Remainder : 0011
Remainder : 0111
Remainder : 1110
Remainder : 1011
Remainder : 0000
Remainder : 0000
Remainder : 0000
Remainder : 0000
Thus a program in Java implemented the Simulation of Error Correction Code (CRC)