Ex No: 1 Basic Network Command: Ping, Netstat, Tracert, Nslookup, Port Scan, Arp, Ipconfig. Ping
Ex No: 1 Basic Network Command: Ping, Netstat, Tracert, Nslookup, Port Scan, Arp, Ipconfig. Ping
Ping:
The ping command helps to verify IP-level connectivity. When
troubleshooting, you can use ping to send an ICMP echo request to a target
host name or IP address. Use ping whenever you need to verify that a host
computer can connect to the TCP/IP network and network resources. Ping is the
primary tool for troubleshooting IP-level connectivity. Type ping -? at a
command prompt to see a complete list of available command-line options. Ping
allows you to specify the size of packets to use (the default is 32 bytes), how
many to send, whether to record the route used, what Time To Live (TTL) value
to use, and whether to set the "don't fragment" flag.
Netstat:
The netstatcommandis aCommand Prompt commandused to display very
detailed information about how your computer is communicating with other
computers or network devices. Specifically, the netstat command can show
details about individual network connections, overall and protocol-specific
networking statistics, and much more, all of which could help troubleshoot
certain kinds of networking issues.
Tracert:
The tracertcommandis aCommand Prompt command, used to show
several details about the path that a packet takes from the computer or device to
destination you specify.A traceroute is a function which traces the path from
one network to another. It allows us to diagnose the source of many problems.
Nslookup:
nslookup (which stands for name server lookup) is a network utility
program used to obtain information about internet servers. As its name suggests,
it finds name server information for domains by querying theDomain
NameSystem(DNS).Nslookup is a useful tool for troubleshooting DNS
problems, such as host name resolution. When you start Nslookup, it shows the
host name and IP address of the DNS server that is configured for the local
system, and then display a command prompt for further queries. If you type a
question mark ( ? ), Nslookup shows all available commands. You can exit the
program by typing exit .
port scan
The most common host-based tool for checking for open ports on
Windows or Unix systems is the netstatcommand. But running this command
means actually walking or remotely accessing each and every server and you
miss other host systems that might be listening on improper ports. This is where
port scanners come in with this tool, a system, network, or security
administrator can check a group of hosts all at once.
ARP:
Address Resolution Protocol (ARP) is a protocol for mapping an
Internet Protocol address (IP address) to a physical machine address that is
recognized in the local network.When you try to ping an IP address on your
local network, say 192.168.1.1, your system has to turn the IP address
192.168.1.1 into a MAC address. This involves using ARP to resolve the
address, hence its name.Systems keep an ARP look-up table where they store
information about what IP addresses are associated with what MAC addresses.
When trying to send a packet to an IP address, the system will first consult this
table to see if it already knows the MAC address. If there is a value cached,
ARP is not used.
If the IP address is not found in the ARP table, the system will then send a
broadcast packet to the network using the ARP protocol to ask "who has
192.168.1.1". Because it is a broadcast packet, it is sent to a special MAC
address that causes all machines on the network to receive it. Any machine with
the requested IP address will reply with an ARP packet that says "I am
192.168.1.1", and this includes the MAC address which can receive packets for
that IP.
Ipconfig:
Ipconfig (sometimes written as IPCONFIG) is a command line tool used
to control the network connections on Windows NT/2000/XP machines.
Ipconfig displays all current TCP/IP network configuration values and refreshes
Dynamic Host Configuration Protocol (DHCP) and Domain Name System
(DNS) settings.
OUTPUT:
PING :
C:\Users\admin>ping gmail.com
Pinging gmail.com [142.250.67.229] with 32 bytes of data:
Reply from 142.250.67.229: bytes=32 time=52ms TTL=115
Reply from 142.250.67.229: bytes=32 time=52ms TTL=115
Reply from 142.250.67.229: bytes=32 time=53ms TTL=115
Reply from 142.250.67.229: bytes=32 time=53ms TTL=115 Ping
statistics for 142.250.67.229:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 52ms, Maximum = 53ms, Average = 52m
NETSTAT:
C:\Users\admin>netstat
Active Connections
Proto Local Address Foreign Address State
TCP 127.0.0.1:49774 ITPC2:49775 ESTABLISHED
TCP 127.0.0.1:49775 ITPC2:49774 ESTABLISHED
TCP 127.0.0.1:52105 ITPC2:52106 ESTABLISHED
TCP 127.0.0.1:52106 ITPC2:52105 ESTABLISHED
TCP 127.0.0.1:52118 ITPC2:52119 ESTABLISHED
TCP 127.0.0.1:52119 ITPC2:52118 ESTABLISHED
TRACERT:
C:\Users\admin>tracert gmail.com Tracing
route to gmail.com [216.58.200.133] over a
maximum of 30 hops:
1 <1 ms 3 ms <1 ms 192.168.49.254
2 3 ms 3 ms 3 ms 210.212.246.130
NSLOOKUP
C:\Users\admin>nslookup gmail.com
Server: dns.google
Address: 8.8.8.8
Name: gmail.com
Addresses: 2404:6800:4007:80b::2005
142.250.183.10
ARP
C:\Users\admin>ARP –A
Interface: 192.168.85.1 --- 0x7
Internet Address Physical Address Type
192.168.85.254 00-50-56-e1-80-22 dynamic
192.168.85.255 ff-ff-ff-ff-ff-ff static
224.0.0.22 01-00-5e-00-00-16 static
224.0.0.251 01-00-5e-00-00-fb static
224.0.0.252 01-00-5e-00-00-fc static
239.255.255.250 01-00-5e-7f-ff-fa static
255.255.255.255 ff-ff-ff-ff-ff-ff static
IPCONFIG
C:\Users\admin>ipconfig
Windows IP Configuration Ethernet
adapter Ethernet:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::7888:b0c6:ecc6:3ce0%12
IPv4 Address. . . . . . . . . . . : 192.168.49.234
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.49.254
EX NO:2 GENERATING HAMMING CODE FOR ERROR DETECTION
AND CORRECTION
PROGRAM:
import java.util.*;
class DanHamming
{ public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the 7-bit data code”);
int d[]=new int[7]; for(int
i=0;i<7;i++)
{ d[i]=sc.nextInt();
} int p[]=new int[4];
p[0]=d[0]^d[1]^d[3]^d[4]^d[6]
;
p[1]=d[0]^d[2]^d[3]^d[5]^d[6]
; p[2]=d[1]^d[2]^d[3];
p[3]=d[4]^d[5]^d[6]; int
c[]=new int[11];
System.out.println(“Complete Code Word is “);
c[0]=p[0]; c[1]=p[1]; c[2]=d[0]; c[3]=p[2];
c[4]=d[1]; c[5]=d[2]; c[6]=d[3]; c[7]=p[3];
c[8]=d[4]; c[9]=d[5]; c[10]=d[6];
for(int i=0; i<11;i++) {
System.out.print(c[i]+ ” “);
}
System.out.println();
System.out.println(“Enter the Received codeword”);
int r[]=new int[11]; for(int i=0;i<11;i++)
{ r[i]=sc.nextInt();
} int pr[]=new
int[4]; int
rd[]=new int[7];
pr[0]=r[0];
pr[1]=r[1];
rd[0]=r[2];
pr[2]=r[3];
rd[1]=r[4];
rd[2]=r[5];
rd[3]=r[6];
pr[3]=r[7];
rd[4]=r[8];
rd[5]=r[9];
rd[6]=r[10]; int
s[]=new int[4];
s[0]=pr[0]^rd[0]^r
d[1]^rd[3]^rd[4]^r
d[6];
s[1]=pr[1]^rd[0]^r
d[2]^rd[3]^rd[5]^r
d[6];
s[2]=pr[2]^rd[1]^r
d[2]^rd[3];
s[3]=pr[3]^rd[4]^r
d[5]^rd[6]; int
dec=(s[0]*1)+
(s[1]*2)+(s[2]*4)+
(s[3]*8);
if(dec==0)
System.out.println(“No error”);
else {
System.out.println(“Error is at “+dec);
if(r[dec-1]==0) r[dec-1]=1; else r[dec-
1]=0;
}
System.out.println(“Corrected code word is : “); for(int
i=0;i<11;i++)
System.out.print(r[i]+” “);
System.out.println();
}
}
SAMPLE OUTPUT:
PROGRAM:
import java.io.*;
class crc
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter Generator:");
String gen = br.readLine();
System.out.println("Enter Data:");
String data = br.readLine(); String
code = data;
while(code.length() < (data.length() + gen.length() - 1))
code = code + "0"; code = data + div(code,gen);
System.out.println("The transmitted Code Word is: " +
code);
System.out.println("Please enter the received Code Word: ");
String rec = br.readLine();
if(Integer.parseInt(div(rec,gen)) == 0)
System.out.println("The received code word contains
no errors."); else
System.out.println("The received code word contains
errors.");
}
static String div(String num1,String num2)
{ int pointer = num2.length();
String result = num1.substring(0, pointer);
String remainder = "";
for(int i = 0; i< num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i)) remainder
+= "0";
else remainder += "1";
}
while(pointer < num1.length())
{ if(remainder.charAt(0) == '0')
{
} remainder = remainder.substring(1, remainder.length());
remainder = remainder +
String.valueOf(num1.charAt(pointer)); pointer++;
}
}
return remainder.substring(1,remainder.length());
}
}
OUTPUT:
Enter Generator:
1010
Enter Data:
10101010
The transmitted Code Word is: 10101010010 Please
enter the received Code Word:
10101010010
The received code word contains no errors.
PROGRAM SENDER:
import java.io.*; import
java.net.*;
importjava.util.Scanner;
class stopwaitsender
{ public static void main(String args[]) throws Exception
{ stopwaitsendersws = new stopwaitsender();
sws.run();
} public void run() throws
Exception
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter no of frames to be sent:”); int
n=sc.nextInt();
Socket myskt=new Socket(“localhost”,9999);
PrintStreammyps=new PrintStream(myskt.getOutputStream());
for(inti=0;i<=n;)
{ if(i==n)
{
myps.println(“exit”); break;
}
System.out.println(“Frame no “+i+” is sent”);
myps.println(i);
BufferedReader bf=new BufferedReader(new
InputStreamReader (myskt. getInputStream ()));
String ack=bf.readLine(); if(ack!=null)
{
System.out.println(“Acknowledgement was Received
from receiver”); i++;
Thread.sleep(4000);
} else
{ myps.println(i);
}
}
}
}
RECEIVER:
import java.io.*;
import java.net.*; class
stopwaitreceiver
{ public static void main(String args[])throws Exception
{ stopwaitreceiver swr = new stopwaitreceiver();
swr.run();
} public void run() throws
Exception
{
String temp="any message",str="exit";
ServerSocket myss=new ServerSocket(9999);
Socket ss_accept=myss.accept();
BufferedReaderss_bf=new BufferedReader(new
InputStreamReader (ss_accept. GetInputStream()));
PrintStream myps=new PrintStream(ss_accept.getOutputStream());
while(temp.compareTo(str)!=0)
{
Thread.sleep(1000); temp=ss_bf.readLine();
if(temp.compareTo(str)==0)
{
break;
}
System.out.println(“Frame “+temp+” was received”);
Thread.sleep(500); myps.println(“Received”);
}
System.out.println(“ALL FRAMES WERE RECEIVED SUCCESSFULLY”);
}
}
OUTPUT:
SENDER:
[usera37@redhatnewit gunaseelan]$ javac stopwaitsender.java
[usera37@redhatnewit gunaseelan]$ java stopwaitsender
PROGRAM:
CLIENT PROGRAM
import java.io.*;
import java.net.*; class
sliclient
{ public static void main(String aafhbasgj[])throws Exception {
PrintStream p; int
no;
p=new PrintStream(s.getOutputStream()); p.println(it);
System.out.println("Enter window size");
no=Integer.parseInt(br.readLine());
p.println(no); int
i=0;
while(intr<it)
{
p.println(msg[i]); i++;
if(i==no)
{ str1=in.readLine();
System.out.println(str1);
} if(i==8)
{ i=0; int r+
+;
}}
ss.close();
s.close();
}
}
OUTPUT:
SERVER:
Enter number of iterations
4
Enter window size
2
ACK : FRAME 0 RECIEVED
ACK : FRAME 1 RECIEVED
ACK : FRAME 2 RECIEVED
ACK : FRAME 3 RECIEVED CLIENT:
project@ubuntu:~/lab/sliding$ java sliclient
0 1 sending ack to
server
2 3 sending ack to
server
4 5 sending ack to
server
0 1 sending ack to
server
2 3 sending ack to
server
4
5
sending ack to server
0 1 sending ack to
server
2 3 sending ack to
server
4 5 sending ack to
server
0 1 sending ack to
server
2 3 sending ack to
server
4 5 sending ack to
server
0 1 sending ack to
server
2
3 sending
ack to server
4 5
sending ack to
server
6 7 sending ack to
server
PROGRAM:
SERVER:
import java.io.*;
import java.net.*; class
UDPServer { public
static DatagramSocket
serversocket; public
static DatagramPacket
dp; public static
BufferedReader dis;
public static
InetAddress ia; public
static byte buf[] = new
byte[1024]; public
static int cport =
789,sport=790; public
static void
main(String[] a)
throws IOException
{ serversocket = new DatagramSocket(sport); dp
= new DatagramPacket(buf,buf.length); dis
= new BufferedReader (new
InputStreamReader(System.in)); ia =
InetAddress.getLocalHost();
System.out.println("Server is Running...");
while(true)
{ serversocket.receive(dp);
String str = new String(dp.getData(), 0,
dp.getLength());
if(str.equals("STOP"))
{
System.out.println("Terminated...");
break;
}
System.out.println("Client: " + str); String
str1 = new String(dis.readLine()); buf =
str1.getBytes(); serversocket.send(new
DatagramPacket(buf,str1.length(), ia, cport)); }
}
}
CLIENT:
import java.io.*;
import java.net.*; class
UDPClient
{ public static DatagramSocket clientsocket; public static
DatagramPacket dp; public static BufferedReader dis;
public static InetAddress ia; public static byte buf[] =
new byte[1024]; public static int cport = 789, sport =
790; public static void main(String[] a) throws
IOException
{
clientsocket = new DatagramSocket(cport);
dp = new DatagramPacket(buf,
buf.length); dis = new
BufferedReader(new
InputStreamReader(System.in)); ia =
InetAddress.getLocalHost();
System.out.println("Client is Running... Type 'STOP'to Quit");
while(true)
{
String str = new String(dis.readLine()); buf
= str.getBytes(); if(str.equals("STOP"))
{
System.out.println("Terminated...");
clientsocket.send(new
DatagramPacket(buf,str.length(), ia,
sport)); break;
}
clientsocket.send(new DatagramPacket(buf,
str.length(), ia, sport));
clientsocket.receive(dp);
String str2 = new String(dp.getData(), 0, dp.getLength());
System.out.println("Server: " + str2);
}
}
}
OUTPUT: CLIENT
project@ubuntu:~/lab/udp$ javac udpclient.java
project@ubuntu:~/lab/udp$ java udpclient
Hello message sent.
Hello
SERVER
project@ubuntu:~/lab/udp$ javac udpserver.java
project@ubuntu:~/lab/udp$ java udpserver
hello
EX NO : 7 IMPLEMENTATION OF TCP
PROGRAM:
CLIENT
import java.net.*; import
java.io.*; public class
ReverseClient {
public static void main(String[] args) {
if (args.length < 2) return;
writer.println(text);
System.out.println(time);
} while (!text.equals("bye"));
socket.close();
while (true) {
Socket socket = serverSocket.accept();
System.out.println("New client connected");
} while (!text.equals("bye"));
socket.close();
}
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. The C++ and the
OTcl are linked together using TclCL. Ns2 is basically an Object Oriented TCL
(OTcl) script interpreter with network simulation event scheduler, network
component object libraries and network setup (plumbing) module libraries.
Network simulator is used for setting up and running a network simulation and user
writes a simulation program in OTcl script language. The OTcl script is used to
initiate the event scheduler, setup the network topology and tell traffic source when
to start and stop sending packets through event scheduler
5. Keep default local package directory as your download folder and click next.
6. Next screen will ask for your Internet connection type keep it as “Direct connection”
and click next and in next screen choose one site to download the packages and click
next.
7. In next screen Cygwin will allow to select the packages you want to install .
8. Uncheck the option “Hide obsolete packages” then click on “view” button till the
word “category” changes to “Full”.
To install NS2 you need to select and install following packages: gcc gcc-g++
gnuplot
make
patch perl
tar
X-startup-scripts xorg-x11-
base xorg-x11-bin xorg-
x11-devel xorg-x11-bin-
dlls xorg-x11-bin-lndir
xorg-x11-etc xorg-x11-fenc
xorg-x11-fnts xorg-x11-
libs-data xorg-x11-xwin
libxt-devel
libXmu-devel
To select a package search the package name and click on word “skip” this will
change it to version number of the package. Do this for all above packages and
click next to start download and installation .
9. Once installation is complete create desktop icons if you need.
NOTE: If you missed any package while installing Cygwin first time you can install
it by running the setup.exe again and selecting the package in step 8.
10. Cygwin installation is complete now you can run Cygwin from desktop and see
its interface.
2. Decompress the file use winrar. Copy the decompressed folder the Cygwin installation
directory under the subdirectory home. It will be C:\
cygwin\home\system_name : where system_name is name of your system in above
Cygwin installation this path will be C:\Cygwin\home\sys27
3. Run Cygwin from desktop and change the directory to folder you copied just now in
step 2 command to change directory: cd /home/sys27/ns-allinone-2.28
This will began the installation process if any Cygwin package is missing it will be
reported to you if so the run Cygwin setu.exe and install the missing package and
start again from step 2.
Working environment.
Why NS2 uses two languages? (TCL and C++)
NS2 uses OTcl to create and configure a network, and uses C++ to run simulation.
All C++ codes need to be compiled and linked to create an executable file. Use OTcl
- For configuration, setup, or one time simulation, or - To run
simulation with existing NS2 modules.
This option is preferable for most beginners, since it does not involve complicated
internal mechanism of NS2. Unfortunately, existing NS2 modules are fairly
limited. This option is perhaps not sufficient for most researchers.
Use C++
- When you are dealing with a packet, or – when you need to
modify existing NS2 modules.
This option perhaps discourages most of the beginners from using NS2. This book
particularly aims at helping the readers understand the structure of NS2 and feel
more comfortable in modifying NS2 modules.
NETWORK ANIMATOR [NAM]
NAM is a Tcl/TK based animation toolfor viewing network simulation traces and
real world packet traces. It supports topology layout, packet level animation, and
various data inspection tools.It has a graphical interface, which can provide
information such as number of packets drops at each link. The network animator
"NAM'' began in 1990 as a simple tool for animating packet trace data. Nam began
at LBL. It has evolved substantially over the past few years.
'nam <nam-file>'
where '<nam-file>' is the name of a NAM trace file that was generated by NS or
one can execute it directly out of the Tcl simulation script for visualization of node
movement.
Platforms: It can be employed in most unix systems (FreeBSD, Linux, Solaris) and
Windows.
Scripting language: It uses TCL as its scripting language OTcl adds object orientation to
TCL.
Protocols implemented in NS2
Transport layer(Traffic Agent) – TCP, UDP
Network layer(Routing agent)
Interface queue – FIFO queue, Drop Tail queue, Priority queue
Logic link contol layer – IEEE 802.2, AR
NS programming Structure
● Create the event scheduler
● Turn on tracing
● Create network topology
● Create transport connections
● Generate traffic
● Insert errors
Tracing ● All
packet trace
$ns traceall[open out.tr w]
<event><time><from><to><pkt><size>
<flowid><src><dst><seqno><aseqno>
+ 0.51 0 1 cbr 500 —– 0 0.0 1.0 0 2
_ 0.51 0 1 cbr 500 —– 0 0.0 1.0 0 2
R 0.514 0 1 cbr 500 —–0 0.0 1.0 0 0
● Variable trace set par [open
output/param.tr w]
$tcp attach $par
$tcp trace cwnd_
$tcp trace maxseq_
$tcp trace rtt_
Creating topology
● Two nodes connected by a
link
Data Sending
PROGRAM
set ns [new Simulator] #define
color for data flows
$ns color 1 Blue $ns color 2
Red #open tracefiles set
tracefile1 [open out.tr w] set
winfile [open winfile w]
$ns trace-all $tracefile1 #open
nam file set namfile [open
out.nam w] $ns namtrace-all
$namfile #define the finish
procedure proc finish {} {
global ns tracefile1 namfile
$ns flush-trace
close $tracefile1 close
$namfile exec nam
out.nam & exit 0
}
#create six nodes set
n0 [$ns node] set n1
[$ns node] set n2
[$ns node] set n3
[$ns node] set n4
[$ns node] set n5
[$ns node] $n1
color Red
$n1 shape box
OUTPUT:
EXNO:10 SIMULATION OF DUPLEX NETWORK
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 6 nodes set
n0 [$ns node] set
n1 [$ns node] set
n2 [$ns node] set
n3 [$ns node] set
n4 [$ns node] set
n5 [$ns node] $n1
color red
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 30
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 30
$ns duplex-link $n3 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n4 30
$ns duplex-link $n3 $n5 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n5 30
$ns simplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 20
$ns simplex-link $n3 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n2 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection set
tcp0 [new Agent/TCP] $ns
attach-agent $n0 $tcp0 set
sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection set
ftp0 [new Application/FTP]
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} { global ns
tracefile namfile $ns
flush-trace close
$tracefile close $namfile
exec nam out.nam & exit
0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
OUTPUT
EXNO:11 SIMULATE A WIRED NETWORK AND MEASURE THE
THROUGHPUT,DELAY,PACKE LOSS
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 10 nodes
set n0 [$ns node] set
n1 [$ns node] set n2
[$ns node] set n3
[$ns node] set n4
[$ns node] set n5
[$ns node] set n6
[$ns node] set n7
[$ns node] set n8
[$ns node] set n9
[$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
$ns duplex-link $n3 $n9 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n9 50
$ns duplex-link $n9 $n8 100.0Mb 10ms DropTail
$ns queue-limit $n9 $n8 50
$ns duplex-link $n8 $n7 100.0Mb 10ms DropTail
$ns queue-limit $n8 $n7 50
$ns duplex-link $n0 $n6 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n6 50
$ns duplex-link $n6 $n5 100.0Mb 10ms DropTail
$ns queue-limit $n6 $n5 50
$ns duplex-link $n5 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n5 $n4 50
$ns duplex-link $n4 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n3 50
$ns duplex-link $n5 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n5 $n0 50
$ns duplex-link $n7 $n5 100.0Mb 10ms DropTail
$ns queue-limit $n7 $n5 50
$ns duplex-link $n5 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n5 $n1 50
$ns duplex-link $n5 $n8 100.0Mb 10ms DropTail
$ns queue-limit $n5 $n8 50
$ns duplex-link $n4 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n2 50
$ns duplex-link $n4 $n9 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n9 50
$ns duplex-link $n6 $n7 100.0Mb 10ms DropTail
$ns queue-limit $n6 $n7 50
#===================================
# Agents Definition
#===================================
#Setup a TCP connection set
tcp0 [new Agent/TCP] $ns
attach-agent $n0 $tcp0 set
sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#Setup a TCP connection set
tcp2 [new Agent/TCP] $ns
attach-agent $n2 $tcp2 set
sink3 [new Agent/TCPSink]
$ns attach-agent $n8 $sink3
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection set
ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
{ delay[i] = -
1;
} } for(i=0; i<count;
i++)
{ if(delay[i] >
0)
{ n_to_n_delay = n_to_n_delay +
delay[i];
}
n_to_n_delay = n_to_n_delay/count;
} printf( "\n") printf("GeneratedPackets =%d\n", seqno+1)
printf("ReceivedPackets = %d\n", receivedPackets) printf("Packet Delivery
Ratio = %.2f\n", receivedPackets/(seqno+1)*100"%") printf("Packet Loss =
%d\n", droppedPackets) printf("Average End-to-End Delay= %.2f\n",
n_to_n_delay * 1000 " ms") printf("\n")
}
THROUGUPUT;
**********
BEGIN {
recvdSize = 0
txsize=0 drpSize=0
startTime = 400
stopTime = 0
thru=0 }
{
Event = $1 time = $2 node_id = $4
pkt_size = $6 level = $5 # Store start
time if (event == "s" && pkt_size
>=512 ) { if (time < startTime)
{ startTime = time
}}
# Update total received packets size and store packets arrival time
if (event == "r" && pkt_size >=512 ) { if (time > stopTime)
{ stopTime = time
}
# Rip off the header
# hdr_size = pkt_size % 512
# pkt_size -= hdr_size
GeneratedPackets =10000
ReceivedPackets = 2376
Packet Delivery Ratio = 237600.00
Packet Loss = 0
Average End-to-End Delay= 03.00
[root@localhost ~]#
PROGRAM:
DISTANCE VECTOR:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr set nf
[open thro.nam w]
$ns rtproto DV
$ns at 45 "finish"
$ns run
LINK STATE
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr set nf
[open thro.nam w]
$ns rtproto LS
$ns at 45 "finish"
$ns run
OUTPUT:
Delay:
******
[root@localhost ~]# awk -f delay.awk thro.tr
GeneratedPackets =200000
ReceivedPackets = 150000
Packet Delivery Ratio = 75.00
Packet Loss = 1.5
Average End-to-End Delay= 0.00001
[root@localhost ~]#
LINKSTATE:
Delay:
******
[root@localhost ~]# awk -f delay.awk thro.tr
GeneratedPackets =200000
ReceivedPackets = 150000
Packet Delivery Ratio = 75.00
Packet Loss = 1.5
Average End-to-End Delay= 0.00001
EX NO:13 EXPERIMENT ON PACKET CAPTURE AND NETWORK
TRAFFIC USING WIRE SHARK TOOL.
When you first launch Wireshark a welcome screen similar to the one shown
above should be visible, containing a list of available network connections on your
current device. In this example, you'll notice that the following connection types are
shown: Bluetooth Network Connection, Ethernet, VirtualBox Host-Only Network, Wi-
Fi. Displayed to the right of each is an EKG-style line graph that represents live traffic on
that respective network.
To begin capturing packets, first select one or more of these networks by clicking
on your choice(s) and using the Shift or Ctrl keys if you'd like to record data from
multiple networks simultaneously. Once a connection type is selected for capturing
purposes, its background will be shaded in either blue or gray. Click on
Capturefrom the main menu, located towards the top of the Wireshark interface.
When the drop-down menu appears, select the Start option.
You can also initiate packet capturing via one of the following shortcuts.
Keyboard: Press Ctrl + E
Mouse: To begin capturing packets from one particular network, simply doubleclick
on its name
Toolbar: Click on the blue shark fin button, located on the far left-hand side of the
Wireshark toolbar
The live capture process will now begin, with packet details displayed in the Wireshark
window as they are recorded. Perform one of the actions below to stop capturing.
Keyboard: Press Ctrl + E
Toolbar: Click on the red stop button, located next to the shark fin on the Wireshark
toolbar
OUTPUT:
Viewing and Analyzing Network Traffic