Network Lab Manual 2019 Print
Network Lab Manual 2019 Print
EX: NO: 1A USE COMMANDS LIKE TCPDUMP, NETSTAT, IFCONFIG, NSLOOKUP, PING AND
TRACEROUTE
AIM:
DESCRIPTION:
TCPDUMP - tcpdump is a common packet analyzer that runs under the command line. It allows the
user to display TCP/IP and other packets being transmitted or received over a network to which the
computer is attached.
NETSTAT - In computing, netstat is a command-line network utility tool that displays network
connections for the Transmission Control Protocol, routing tables, and a number of network interface
and network protocol statistics.
IFCONFIG – ifconfig is a system administration utility in Unix-like operating systems for network
interface configuration. The utility is a command-line interface tool and is also used in the system
startup scripts of many operating systems.
PING - Ping is a computer network administration software utility used to test the reachability of a
host on an Internet Protocol network.
TRACEROUTE - Traceroute helps you analyze the path packets take on a network, along with any
associated delays.
COMMANDS:
1.TCPDUMP
$ which tcpdump
/usr/sbin/tcpdump
Resolving Dependencies
--> Running transaction check
---> Package tcpdump.x86_64 14:4.0.0-5.20090921gitdf3cb4.2.el6 will
be updated
---> Package tcpdump.x86_64 14:4.0.0-11.20090921gitdf3cb4.2.el6 will
be an update
--> Finished Dependency Resolution
Dependencies Resolved
$ tcpdump -i any
[root@localhost ~]# tcpdump -i any
2.NETSTAT
# netstat -a | more
[root@localhost ~]# netstat -a / more
s_socket
unix 3 [ ] STREAM CONNECTED 12283
unix 2 [ ] DGRAM 12279
unix 3 [ ] STREAM CONNECTED 12249
/var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 12248
unix 3 [ ] STREAM CONNECTED 12242
unix 3 [ ] STREAM CONNECTED 12241
unix 2 [ ] DGRAM 12073
unix 3 [ ] STREAM CONNECTED 11593
unix 3 [ ] STREAM CONNECTED 11592
unix 3 [ ] STREAM CONNECTED 11583
unix 3 [ ] STREAM CONNECTED 11582
unix 3 [ ] DGRAM 8499
unix 3 [ ] DGRAM 8498
netstat –at
netstat –au
[root@localhost ~]# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address
State
udp 0 0 *:dhcp-failover *:*
udp 0 0 *:imap *:*
udp 0 0 *:783 *:*
udp 0 0 *:58673 *:*
udp 0 0 192.168.122.1:domain *:*
udp 0 0 *:bootps *:*
udp 0 0 *:bootpc *:*
unix/X0
unix 2 [ ACC ] STREAM LISTENING 14671
/var/run/libvirt/libvirt-sock
# netstat –s
IpExt:
InBcastPkts: 17
InOctets: 567702
OutOctets: 212164
InBcastOctets: 5328
3. IFCONFIG
# ifconfig
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr A0:48:1C:A4:1E:0C
inet addr:10.10.113.79 Bcast:10.10.113.255
Mask:255.255.255.0
inet6 addr: fe80::a248:1cff:fea4:1e0c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1264 errors:0 dropped:0 overruns:0 frame:0
TX packets:300 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:433958 (423.7 KiB) TX bytes:18540 (18.1 KiB)
# ifconfig -a
eth0 Link encap:Ethernet HWaddr A0:48:1C:A4:1E:0C
inet addr:10.10.113.79 Bcast:10.10.113.255
Mask:255.255.255.0
inet6 addr: fe80::a248:1cff:fea4:1e0c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1293 errors:0 dropped:0 overruns:0 frame:0
TX packets:300 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
4. NSLOOKUP
# nslookup google.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: google.com
Address: 216.58.196.174
5.PING
1. Ping the host to see if its alive
$ ping google.com
[root@localhost ~]# ping google.com
PING google.com (172.217.163.46) 56(84) bytes of data.
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=1
ttl=57 time=2.41 ms
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=2
ttl=57 time=2.00 ms
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=3
ttl=57 time=2.08 ms
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=4
ttl=57 time=3.75 ms
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=5
ttl=57 time=2.22 ms
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=6
ttl=57 time=1.93 ms
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=7
ttl=57 time=2.05 ms
6.TRACE ROUTE
$ traceroute google.com
traceroute to google.com (172.217.163.46), 30 hops max, 60 byte
packets
1 * * *
2 192.168.1.2 (192.168.1.2) 0.229 ms 0.447 ms 0.422 ms
3 220.225.121.206 (220.225.121.206) 1.497 ms 1.156 ms PTPL-
AS56272-REV-137.108.254.43-CHN.PULSE.IN (43.254.108.137) 116.834 ms
4 182.79.198.6 (182.79.198.6) 10.556 ms * *
5 * as15169.maa.extreme-ix.net (45.120.251.135) 121.042 ms
72.14.211.198 (72.14.211.198) 3.526 ms
6 * * *
7 216.239.42.215 (216.239.42.215) 120.869 ms 3.552 ms
74.125.51.2 (74.125.51.2) 2.466 ms
8 74.125.242.129 (74.125.242.129) 3.833 ms maa05s01-in-
f14.1e100.net (172.217.163.46) 117.253 ms 3.565 ms
Result:
Thus the commands TCPdump, Netsatat,Ping and Traceroute has been implemented successfully.
PROTOCOL ANALYZER
DESCRIPTION
Wireshark is a software protocol analyzer, or "packet sniffer" application, used for network
troubleshooting, analysis, software and protocol development, and education. t has a rich and
powerful feature set and runs on most computing platforms including Windows, OS X, Linux, and
UNIX. Network professionals, security experts, developers, and educators around the world use it
regularly. It is freely available as open source, and is released under the GNU General Public License
version 2.
Steps:
1. Open Wireshark application
2. To start PDU capture, go to Capture on the Menu bar and select Options. The Capture
Options dialog box provides a range of settings and filters which determines which and how
much data traffic is captured.
3. Ensure that Wireshark is set to monitor the correct interface.
4. Click the Start button on the Wireshark: Capture Options window. This would show a
Capture Information Dialog, and the Main Display Window would then be divided into
different panes similar to the window
5. When the Stop button is clicked, the capture process is terminated, and the main screen is
displayed. This Main Display Window of Wireshark has three panes. a. Packet List pane
b.Packet Details Pane c.Packet bytes pane.
Result:
Thus the commands and caputing of Ping and Traceroute completed successfully.
EX:NO:2 HTTP web client program to download a web page using TCP sockets
AIM:
To write a HTTP web client program to download a web page using TCP sockets.
ALGORITHM :
Steps:
1. Create a URL object and pass url as string to download the webpage.
URL example = new URL(pass url of webpage you want to download)
2. Create Buffered Reader object and pass openStream(). Method of URL in Input Stream object.
3. Create a string object to read each line one by one from stream.
4. Write each line in html file where webpage will be downloaded.
5. Close all objects.
6. Catch exceptions if url failed to download.
PROGRAM
import java.io.*;
import java.net.*;
try {
Socket socket = new Socket(hostName, portNumber);
PrintWriter out =
new PrintWriter(socket.getOutputStream(), true);
BufferedReader in =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));
out.println("GET / HTTP/1.1\nHost: www.martinbroadhurst.com
\n\n");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " +
hostName);
System.exit(1);
}
}
}
Output:
2118
<!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" lang="en-US">
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" lang="en-US">
<![endif]-->
<!--[if !(IE 7) & !(IE 8)]><!-->
<html lang="en-US">
<!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Martin Broadhurst</title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback"
href="http://www.martinbroadhurst.com/xmlrpc.php">
<!--[if lt IE 9]>
<script src="http://www.martinbroadhurst.com/wp-
content/themes/twentyfourteen/js/html5.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml" title="Martin
Broadhurst » Feed" href="http://www.martinbroadhurst.com/feed" />
<link rel="alternate" type="application/rss+xml" title="Martin Broadhurst
» Comments Feed"
href="http://www.martinbroadhurst.com/comments/feed" />
<link rel="alternate" type="application/rss+xml" title="Martin Broadhurst
» Martin Broadhurst Comments Feed"
href="http://www.martinbroadhurst.com/sample-page/feed" />
<script type="text/javascript">
window._wpemojiSettings =
{"baseUrl":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png",
"source":{"concatemoji":"https:\/\/round-lake.dustinice.workers.dev:443\/http\/www.martinbroadhurst.com\/wp-
includes\/js\/wp-emoji-release.min.js?ver=4.5"}};
!function(a,b,c){function d(a){var
c,d,e,f=b.createElement("canvas"),g=f.getContext&&f.getContext("2d"),h=Str
ing.fromCharCode;if(!g||!g.fillText)return!1;switch(g.textBaseline="top",g
.font="600 32px Arial",a){case"flag":return
g.fillText(h(55356,56806,55356,56826),0,0),f.toDataURL().length>3e3;case"d
iversity":return
g.fillText(h(55356,57221),0,0),c=g.getImageData(16,16,1,1).data,g.fillText
(h(55356,57221,55356,57343),0,0),c=g.getImageData(16,16,1,1).data,e=c[0]+"
,"+c[1]+","+c[2]+","+c[3],d!==e;case"simple":return
g.fillText(h(55357,56835),0,0),0!==g.getImageData(16,16,1,1).data[0];case"
unicode8":return
g.fillText(h(55356,57135),0,0),0!==g.getImageData(16,16,1,1).data[0]}retur
n!1}function e(a){var
c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElements
ByTagName("head")[0].appendChild(c)}var
f,g,h,i;for(i=Array("simple","flag","unicode8","diversity"),c.supports={ev
erything:!0,everythingExceptFlag:!0},h=0;h<i.length;h++)c.supports[i[h]]=d
(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag
"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag
&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingE
xceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOM
Ready=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEve
ntListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener
("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechang
e",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||
{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.
wpemoji)))}(window,document,window._wpemojiSettings);
</script>
<style type="text/css">
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 .07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}
</style>
<link rel='stylesheet' id='twentyfourteen-lato-css'
href='https://fonts.googleapis.com/css?family=Lato%3A300%2C400%2C700%2C900
%2C300italic%2C400italic%2C700italic&subset=latin%2Clatin-ext'
type='text/css' media='all' />
<link rel='stylesheet' id='genericons-css'
href='http://www.martinbroadhurst.com/wp-
content/themes/twentyfourteen/genericons/genericons.css?ver=3.0.3'
type='text/css' media='all' />
<link rel='stylesheet' id='twentyfourteen-style-css'
href='http://www.martinbroadhurst.com/wp-
content/themes/twentyfourteen/style.css?ver=4.5' type='text/css'
media='all' />
<!--[if lt IE 9]>
<link rel='stylesheet' id='twentyfourteen-ie-css'
href='http://www.martinbroadhurst.com/wp-
content/themes/twentyfourteen/css/ie.css?ver=20131205' type='text/css'
media='all' />
<![endif]-->
<script type='text/javascript' src='http://www.martinbroadhurst.com/wp-
includes/js/jquery/jquery.js?ver=1.12.3'></script>
<script type='text/javascript' src='http://www.martinbroadhurst.com/wp-
includes/js/jquery/jquery-migrate.min.js?ver=1.4.0'></script>
<link rel='https://api.w.org/' href='http://www.martinbroadhurst.com/wp-
json/' />
<link rel="EditURI" type="application/rsd+xml" title="RSD"
href="http://www.martinbroadhurst.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml"
href="http://www.martinbroadhurst.com/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 4.5" />
<link rel="canonical" href="http://www.martinbroadhurst.com/" />
<link rel='shortlink' href='http://www.martinbroadhurst.com/' />
<link rel="alternate" type="application/json+oembed"
href="http://www.martinbroadhurst.com/wp-
json/oembed/1.0/embed?url=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttp%2Fwww.martinbroadhurst.com%2F" />
<link rel="alternate" type="text/xml+oembed"
href="http://www.martinbroadhurst.com/wp-
json/oembed/1.0/embed?url=https%3A%2F%2Fround-lake.dustinice.workers.dev%3A443%2Fhttp%2Fwww.martinbroadhurst.com%2F&fo
rmat=xml" />
<style type="text/css">.recentcomments a{display:inline
!important;padding:0 !important;margin:0 !important;}</style>
<style type="text/css" id="syntaxhighlighteranchor"></style>
</head>
Result:
Thus a HTTP web client program to download a web page using TCP sockets been done and
executed successfully.
AIM:
To write a java program for the application of TCP sockets – Echo client and Echo Server.
ALGORITHM:
1. Start the program
2. Establish a socket connection, The java.net.Socket class represents a Socket
3. Input streams and output streams are used to communicate over a socket connection for both
input and output the data.
4. Server makes a new Socket to communicate with the client.
5. The accept() method blocks, until a client connects to the server.
6. A ServerSocket which waits for the client requests (when a client makes a new
Socket())
7. getOutputStream() method is used to send the output through the socket.
8. Close the connection by closing the socket and the input stream.
PROGRAM:
SERVER PROGRAM:
import java.net.*;
import java.io.*;
public class Server
{
public static void main( String args[]) throws Exception
{
ServerSocket srs = new ServerSocket(1234);
System.out.println("Server is running...");
Socket ss=srs.accept();
System.out.println("connection establised");
BufferedReader kb = new BufferedReader(new
InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new
InputStreamReader(ss.getInputStream()));
DataOutputStream dos = new DataOutputStream(ss.getOutputStream());
while(true)
{
//System.out.println("server repeat as long as client not send
null");
String s2,s3;
while((s2=br.readLine())!=null)
{
System.out.println("Client said : "+s2);
System.out.println("Enter text ");
s3 = kb.readLine();
//System.out.println("Answer send to client machine");
dos.writeBytes(s3+"\n");
}
System.out.println("Terminated..");
ss.close();
srs.close();
dos.close();
kb.close();
System.exit(0);
}
}
}
CLIENT PROGRAM:
import java.net.*;
import java.io.*;
public class Client
{
public static void main( String args[]) throws Exception
{
Socket cs = new Socket("localhost",1234);
BufferedReader kb = new BufferedReader(new
InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new
InputStreamReader(cs.getInputStream()));
DataOutputStream dos = new
DataOutputStream(cs.getOutputStream());
String s1,s4=null;
while(!(s1=kb.readLine()).equals("exit"))
{
//System.out.println(" data send to server machine");
dos.writeBytes(s1+"\n");
s4 = br.readLine();
//System.out.println(" data receive from server
machine");
System.out.println("Server said : "+s4);
System.out.println("Enter text ");
}
System.out.println("Terminated..");
cs.close();
dos.close();
kb.close();
}
}
Output:
Result:
AIM:
To write a java program for the application of TCP sockets like CHAT.
ALGORITHM:
1. In any Client/Server Application, run the server before the client, because the server keeps waiting for
the client to be connected.
2. Server keeps listening for the client on an assigned IP & Port
3. For establishing connection client must know the IP & Port of the server.
4. When we start Client Application, It creates a connection to the server.
5. After the Successful connection Client & Server Applications can send & receive messages
CLIENT PROGRAM:
import java.net.*;
import java.io.*;
public class Client1
{
public static void main( String args[]) throws Exception
{
Socket cs = new Socket("localhost",1234);
BufferedReader kb = new BufferedReader(new
InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new
InputStreamReader(cs.getInputStream()));
DataOutputStream dos = new DataOutputStream(cs.getOutputStream());
String s1,s4=null;
while(!(s1=kb.readLine()).equals("exit"))
{
//System.out.println(" data send to server machine");
dos.writeBytes(s1+"\n");
s4 = br.readLine();
//System.out.println(" data receive from server machine");
System.out.println("Server said : "+s4);
System.out.println("Enter text ");
}
System.out.println("Terminated..");
cs.close();
dos.close();
kb.close();
}
}
SERVER PROGRAM:
import java.net.*;
import java.io.*;
public class Server1
{
public static void main( String args[]) throws Exception
{
ServerSocket srs = new ServerSocket(1234);
System.out.println("Server is running...");
Socket ss=srs.accept();
System.out.println("connection establised");
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new
InputStreamReader(ss.getInputStream()));
DataOutputStream dos = new DataOutputStream(ss.getOutputStream());
while(true)
{
//System.out.println("server repeat as long as client not send null");
String s2,s3;
while((s2=br.readLine())!=null)
{
System.out.println("Client said : "+s2);
System.out.println("Enter text ");
s3 = kb.readLine();
//System.out.println("Answer send to client machine");
dos.writeBytes(s3+"\n");
}
System.out.println("Terminated..");
ss.close();
srs.close();
dos.close();
kb.close();
System.exit(0);
}
}
}
Output:
Server
Enter text
ok
Client
[user@localhost sample]$ javac Client1.java
[user@localhost sample]$ java Client1
Enter text..
if client 'quit' type exit
hi
Server said : how are u?
Enter text
fine.
Server said : ok
Result:
AIM:
To write a java program for the application of TCP sockets like FILE TRANSFER.
ALGORITHM:
1. Start the program
2. Initialize the sockets.
3. Accept the client connection using the socket descriptor and the server address
4. Using File reader and buffered reader read the file which is created in the client program.
5. In the client program the file is created and data is entered.
6. Open the file and read the line line by line and write bytes.
7. Display the content from the file on the console.
8. Close the connection
9. Stop the program
SERVER PROGRAM
import java.io.*;
import java.net.*;
import java.util.*;
class Serverfile
{ public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
while(true)
{
Socket obj1=obj.accept();
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
FileReader f=new FileReader(str);
BufferedReader b=new BufferedReader(f);
String s;
while((s=b.readLine())!=null)
{ System.out.println(s);
dout.writeBytes(s+'\n');
}
f.close();
dout.writeBytes("-1\n");
} }
catch(Exception e)
{ System.out.println(e);}
}}
CLIENT PROGRAM
import java.io.*;
import java.net.*;
import java.util.*;
class Clientfile
{ public static void main(String args[])
{
Try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the file name:");
String str=in.readLine();
dout.writeBytes(str+'\n');
System.out.println("Enter the new file name:");
String str2=in.readLine();
String str1,ss;
FileWriter f=new FileWriter(str2);
char buffer[];
while(true)
{ str1=din.readLine();
if(str1.equals("-1")) break;
System.out.println(str1);
buffer=new char[str1.length()];
str1.getChars(0,str1.length(),buffer,0);
f.write(buffer);
}
f.close();
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}}}
OUTPUT:
SERVER
[user@localhost Desktop]$ javac Serverfile.java
[user@localhost Desktop]$ java Serverfile
Hii
Hello
Welcome
This is my file
CLIENT
[user@localhost Desktop]$ javac Clientfile.java
[user@localhost Desktop]$ java Clientfile
Enter the filename:
myfile.txt
Result: The simulation program to implement TCP file transfer is implemented successfully.
AIM:
To implement a DNS server and client in java using UDP sockets.
ALGORITHM:
Server
1. Create an array of hosts and its ip address in another array
2. Create a datagram socket and bind it to a port
3. Create a datagram packet to receive client request
4. Read the domain name from client to be resolved
5. Lookup the host array for the domain name
6. If found then retrieve corresponding address
7. Create a datagram packet and send ip address to client
8. Repeat steps 3-7 to resolve further requests from clients
9. Close the server socket
10. Stop
Client
1. Create a datagram socket
2. Get domain name from user
3. Create a datagram packet and send domain name to the server
4. Create a datagram packet to receive server message
5. Read server's response
6. If ip address then display it else display "Domain does not exist"
7. Close the client socket
8. Stop
.
PROGRAM
// UDP DNS Server -- udpdnsserver.java
import java.io.*;
import java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str))
return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com",
"facebook.com"};
String[] ip = {"68.180.206.184",
"209.85.148.19","80.168.92.140","69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");
while (true)
{
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new
DatagramPacket(receivedata, receivedata.length);
serversocket.receive(recvpack);
String sen = new String(recvpack.getData());
InetAddress ipaddress = recvpack.getAddress();
int port = recvpack.getPort();
String capsent;
System.out.println("Request for host " + sen);
if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts, sen)];
else
capsent = "Host Not Found";
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,
senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}
}
}
SERVER:
CLIENT:
[user@localhost Desktop]$ javac udpdnsclient.java
[user@localhost Desktop]$ java udpdnsclient
Enter the hostname:
yahoo.com
IPAddress:68.180.206.184
Result:
Thus the DNS simulation program using UDP Sockets is implemented successfully.
Aim:
Algorithm:
server
1. Create a server socket and bind it to port.
2. Listen for new connection and when a connection arrives, accept it.
3. Send servers date and time to the client.
4. Read clients IP address sent by the client.
5. Display the client details.
6. Repeat steps 2-5 until the server is terminated.
7. Close all streams.
8. Close the server socket.
9. Stop.
Client
1. Create a client socket and connect it to the server‟ s port number.
2. Retrieve its own IP address using built-in function.
3. Send its address to the server.
4. Display the date & time sent by the server.
5. Close the input and output streams.
6. Close the client socket.
7. Stop.
Program
Program for Address Resolutuion Protocol (ARP) using TCP
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
{
public static void main(String args[])
{
Try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Logical address(IP):");
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
System.out.println("The Physical Address is: "+str);
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
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);
}
}
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Physical address (MAC):");
}
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s); 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(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
ARP:
SERVER:
[user@localhost Desktop]$ javac Serverarp.java
[user@localhost Desktop]$ java Serverarp
CLIENT:
[user@localhost Desktop]$ javac Clientarp.java
[user@localhost Desktop]$ java Clientarp
Enter the logical address(IP):
165.165.80.80
The Physical Address is:6A:08:AA:C2
RARP:
SERVER:
[user@localhost Desktop]$ javac Serverrarp12.java
[user@localhost Desktop]$ java Serverrarp12
CLIENT:
[user@localhost Desktop]$ javac Clientrarp12.java
[user@localhost Desktop]$ java Clientrarp12
Enter the physical address(MAC):
6A:08:AA:C2
The Logical Address is (IP):165.165.80.80
Result:
Thus the simulation program for ARP/RARP protocol is implemented successfully.
AIM:
DESCRIPTION:
ns is an object oriented simulator, written in C++, with an OTcl interpreter as a frontend. The
simulator supports a class hierarchy in C++ (also called the compiled hierarchy in this document),
and a similar class hierarchy within the OTcl interpreter (also called the interpreted hierarchy in this
document). The two hierarchies are closely related to each other; from the user’s perspective, there is
a one-to-one correspondence between a class in the interpreted hierarchy and one in the compiled
hierarchy. The root of this hierarchy is the class TclObject. Users create new simulator objects through
the interpreter; these objects are instantiated within the interpreter, and are closely mirrored by a
corresponding object in the compiled hierarchy. The interpreted class hierarchy is automatically
established through methods defined in the class TclClass. User instantiated objects are mirrored
through methods defined in the class TclObject. There are other hierarchies in the C++ code and OTcl
scripts; these other hierarchies are not mirrored in the manner of TclObject.
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 requires 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 exploringa 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. C++ is fast to run but slower to change, making it
suitable for detailed protocol implementation. OTcl runs much slower but can be changed very
quickly (and interactively), making it ideal for simulation configuration. ns (via tclcl) provides glue to
make objects and variables appear on both langauges.
SIMULATOR INITIALIZATION:
When a new simulation object is created in tcl, the initialization procedure performs the
following operations:
• initialize the packet format (calls create_packetformat)
• create a scheduler (defaults to a calendar scheduler)
• create a “null agent” (a discard sink used in various places)
NODE BASICS:
The basic primitive for creating a node is
set ns [new Simulator]
$ns node
The instance procedure node constructs a node out of more simple classifier objects (Section 5.4). The
Node itself is a standalone class in OTcl. However, most of the components of the node are
themselves TclObjects. The typical structure of a (unicast) node is as shown in Figure 5.1. This simple
structure consists of two TclObjects: an address classifer (classifer_) and a port classifier (dmux_). The
function of these classifiers is to distribute incoming packets to the correct agent or outgoing link.
All nodes contain at least the following components:
an address or id_, monotonically increasing by 1 (from initial value 0) across the simulation
namespace as nodes are created,
a list of neighbors (neighbor_),
set ns [new Simulator]: generates an NS simulator object instance, and assigns it to variable ns.The
"Simulator" object has member functions that do the following:
$ns color fid color: is to set color of the packets for a flow specified by the flow id (fid). This
member function of "Simulator" object is for the NAM display, and has no effect on the actual
simulation.
$ns namtrace-all file-descriptor: This member function tells the simulator to record simulation
traces in NAM input format. It also gives the file name that the trace will be written to later by
the command $ns flush-trace. Similarly, the member function trace-all is for recording the
simulation trace in a general format.
proc finish {}: is called after this simulation is over by the command $ns at 5.0 "finish". In this
function, post-simulation processes are specified.
set n0 [$ns node]: The member function node creates a node. A node in NS is compound
object made of address and port classifiers (described in a later section). Users can create a
node by separately creating an address and a port classifier objects and connecting them
together. However, this member function of Simulator object makes the job easier. To see how
a node is created, look at the files: "ns-2/tcl/libs/ns-lib.tcl"andns-2/tcl/libs/ns-node.tcl".
$ns duplex-link node1 node2 bandwidth delay queue-type: creates two simplex links of specified
bandwidth and delay, and connects the two specified nodes. In NS, the output queue of a
node is implemented as a part of a link, therefore users should specify the queue-type when
creating links. In the above simulation script, DropTail queue is used. If the reader wants to
use a RED queue, simply replace the word DropTail with RED. The NS implementation of a
link is shown in a later section. Like a node, a link is a compound object, and users can create
its sub-objects and connect them and the nodes. Link source codes can be found in "ns-
2/tcl/libs/ns-lib.tcl" and "ns-2/tcl/libs/ns-link.tcl" files. One thing to note is that you can
insert error modules in a link component to simulate a lossy link (actually users can make and
insert any network objects). Refer to the NS documentation to find out how to do this.
$ns queue-limit node1 node2 number: This line sets the queue limit of the two simplex links that
connect node1 and node2 to the number specified. At this point, the authors do not know how
many of these kinds of member functions of Simulator objects are available and what they are.
Please take a look at "ns-2/tcl/libs/ns-lib.tcl" and "ns-2/tcl/libs/ns-link.tcl", or NS.
$ns duplex-link-op node1 node2 ...: The next couple of lines are used for the NAM display. To
see the effects of these lines, users can comment these lines out and try the simulation.
Now that the basic network setup is done, the next thing to do is to setup traffic agents such
as TCP and UDP, traffic sources such as FTP and CBR, and attach them to nodes and agents
respectively.
set tcp [new Agent/TCP]: This line shows how to create a TCP agent. But in general, users can
create any agent or traffic sources in this way. Agents and traffic sources are in fact basic
objects (not compound objects), mostly implemented in C++ and linked to OTcl. Therefore,
there are no specific Simulator object member functions that create these object instances. To
create agents or traffic sources, a user should know the class names these objects (Agent/TCP,
Agnet/TCPSink, Application/FTP and so on). This information can be found in the NS
documentation or partly in this documentation. But one shortcut is to look at the
"ns2/tcl/libs/ns-default.tcl" file. This file contains the default configurable parameter value
settings for available network objects. Therefore, it works as a good indicator of what kind of
network objects are available in NS and what are the configurable parameters.
$ns attach-agent node agent: The attach-agent member function attaches an agent object created
to a node object. Actually, what this function does is call the attach member function of
specified node, which attaches the given agent to itself. Therefore, a user can do the same
thing by, for example, $n0 attach $tcp. Similarly, each agent object has a member function .
$ns connect agent1 agent2: After two agents that will communicate with each other are created,
the next thing is to establish a logical network connection between them. This line establishes
a network connection by setting the destination address to each others' network and port
address pair.
Assuming that all the network configuration is done, the next thing to do is write a simulation
scenario (i.e. simulation scheduling). The Simulator object has many scheduling member
functions. However, the one that is mostly used is the following:
$ns at time "string": This member function of a Simulator object makes the scheduler
(scheduler_ is the variable that points the scheduler object created by [new Scheduler]
command at the beginning of the script) to schedule the execution of the specified string at
given simulation time. For example, $ns at 0.1 "$cbr start" will make the scheduler call a start
member function of the CBR traffic source object, which starts the CBR to transmit data. In
NS, usually a traffic source does not transmit actual data, but it notifies the underlying agent
that it has some amount of data to transmit, and the agent, just knowing how much of the
data to transfer, creates packets and sends them.
After all network configuration, scheduling and post-simulation procedure specifications are
done, the only thing left is to run the simulation. This is done by $ns run.
RESULT:
AIM:
To simulate a link failure and observe the congestion control algorithm using NS2.
ALGORITHM:
1. Create a simulation object
2. Set routing protocol to routing
3. Trace packets and all links onto NAM trace and to trace file
4. Create right nodes
5. Describe their layout topology as octagon
6. Add a sink agent to node
7. Connect source and sink.
PROGRAM:
set ns [new Simulator]
set nr [open thro_red.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0 }
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]
$ns duplex-link $n0 $n3 1Mb 10ms RED
$ns duplex-link $n1 $n3 1Mb 10ms RED
$ns duplex-link $n2 $n3 1Mb 10ms RED
$ns duplex-link $n3 $n4 1Mb 10ms RED
$ns duplex-link $n4 $n5 1Mb 10ms RED
$ns duplex-link $n4 $n6 1Mb 10ms RED
$ns duplex-link $n4 $n7 1Mb 10ms RED
$ns duplex-link-op $n0 $n3 orient right-up
$ns duplex-link-op $n3 $n4 orient middle
$ns duplex-link-op $n2 $n3 orient right-down
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n7 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n6 $n4 orient left
set udp0 [new Agent/UDP]
Output:
RESULT:
Thus the program for Congestion control is implemented in NS2 sucessfully.
Aim:
The aim is to study the performance of TCP/UDP using Simulation tool(NS2).
DESCRIPTION:
Network Simulator (Version 2), widely known as NS2,simulation tool which is meant for studying
dynamic nature of communication i.e. for both wired and wireless network functions and for routing
algorithms, TCP, UDP protocols. Basically it provides specific way of simulating such network
protocols.
TCP
The important protocol is Transmission Control Protocol (TCP) used for transmission in a network.
Internet widely uses TCP protocol for data transmission in communication network. In order to
perform transmission connection is established between the client and the server. Connection is
initiated by the Client and sends Sequence number along with the segment. So the Server
acknowledges it back with its own Sequence number and ACK of client’s segment which is one more
than client’s Sequence number. Client after receiving ACK of its segment sends an acknowledgement
of Server’s response.
UDP
The User Datagram Protocol (UDP) is simplest Transport Layer communication protocol available of
the TCP/IP protocol suite. Communication mechanism involved is minimum. UDP is an unreliable
transport protocol which uses IP services to provide best delivery mechanism. In UDP, there is no
generation of acknowledgement of received packets to sender and senders do not wait for any
acknowledgement in turn of packet. This makes UDP protocol unreliable on processing. UDP is
implemented where packet acknowledgement have same significance on bandwidth as that actual
data. In case of video streaming, thousands of packets are generated towards its users.
Acknowledging all those packets is troublesome and which results in huge amount of bandwidth
wastage.
Result:
Thus the study for the performance measures of TCP and UDP is done successfully.
AIM:
To simulate and study the Distance Vector routing algorithm using simulation.
SOFTWARE REQUIRED:
NS-2
THEORY:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network for computing
shortest path
between source and destination. The Router is one main devices used in a wide area network. The
main task of
the router is Routing. It forms the routing table and delivers the packets depending upon the routes
in the tableeither directly or via an intermediate devices.
Each router initially has information about its all neighbors. Then this information will be shared
among nodes.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam on
trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
RESULT:
Thus the Distance Vector routing algorithm is implemented successfully.
AIM:
To simulate and study the link state routing algorithm using simulation.
SOFTWARE REQUIRED:
NS-2
THEORY:
In link state routing, each router shares its knowledge of its neighborhood with every other router in
the internet work. (i) Knowledge about Neighborhood: Instead of sending its entire routing table a
router sends info about its neighborhood only. (ii) To all Routers: each router sends this information
to every other router on the internet work not just to its neighbor .It does so by a process called
flooding. (iii)Information sharing when there is a change: Each router sends out information about
the neighbors when there is change.
PROCEDURE:
The Dijkstra algorithm follows four steps to discover what is called the shortest path tree(routing
table) for each router:The algorithm begins to build the tree by identifying its roots. The root router’s
trees the router itself. The algorithm then attaches all nodes that can be reached from the root. The
algorithm compares the tree’s temporary arcs and identifies the arc with the lowest cumulative cost.
This arc and the node to which it connects are now a permanent part of the shortest path tree. The
algorithm examines the database and identifies every node that can be reached from its chosen node.
These nodes and their arcs are added temporarily to the tree.
The last two steps are repeated until every node in the network has become a permanent part of the
tree.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam on
trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose Link state routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto LS
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run
RESULT
Thus the simulation of Link State routing algorithm is implemented in NS2 sucessfully.
AIM:
To evaluate the performance of routing protocols using NS2 simulation tool.
ALGORITHM:
1. Set ns as new simulator
2. Create a simulation for multicast routing protocol
3. Create nodes with duplex link
4. Allocate multicast addresses
5. Create multicast capable nodes
6. set RV and bootstrap points
7. Configure Multicast protocol
8. Attach Transport agent for the traffic source
9. Create receiver and set receiver
PROGRAM:
proc finish {} {
global ns
$ns flush-trace
exec nam out.nam &
exit 0
}
$ns run
RESULT
Thus the program for multicast routing protocol has been implemented successfully in NS2.
AIM:
To simulate Error Correction Code (CRC).
ALGORITHM:
PROGRAM:
import java.util.*;
class CRC {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n;
AIM:
To Simulate and to study of Go Back N protocol
THEORY:
Go Back N is a connection oriented transmission. The sender transmits the frames continuously. Each frame in
the buffer has a sequence number starting from 1 and increasing up to the window size. The sender has a
window i.e. a buffer to store the frames. This buffer size is the number of frames to be transmitted continuously.
The size of the window depends on the protocol designer.
ALGORITHM :
RESULT:
Thus the program for GO BACK N Protocol is implemented successfully in NS2.
AIM:
To simulate the performance of Stop wait protocol using ns2.
ALGORITHM:
Step 1: Start the program
Step 2: Create the trace file and NAM file.
Step 3: Setup the topology object
Step 4: Create nodes and set duplex links between the nodes.
Step 5: Create nodes and attach them to the queue, DROPTAIL
Step 6: Configure the nodes and provides initial location of nodes. Generation of movements is done.
Step 7: Setup a TCP Connection between nodes
Step 8: Define a initialize positions for the nam window.
Step 9: Telling nodes when the simulation ends
Step 10: Ending nam and the simulation
PROGRAM:
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP]
$tcp set window 1
$tcp set maxcwnd 1
$tcp set fid 1
$ns attach-agent $n0 $tcp
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam stopwait.nam &
exit 0
}
$ns run
OUTPUT:
STOP WAIT PROTOCOL:
RESULT:
Thus the program to implement Stopwait protocol in NS2 sucessfully.