Professional Documents
Culture Documents
CS8581 Lab Manual
CS8581 Lab Manual
SEMESTER:III REGULATION:2017
SUB CODE: CS8581 SUB NAME: NETWORKS LABORATORY
Prepared By Approved By
R.S. Pratheeba,AP/CSE
Approved on :
VISION
● To be a centre of excellence in engineering and technology
● To produce technocrats who are technically competent, ethically strong for
advancement of the society.
MISSION
● To provide quality education in emerging technologies in accordance with
industrial trends.
● To build good research capabilities and support new innovations.
Vision
● To enhance young professionals to compete the global challenges in the field of
computer science and engineering to pursue research in this field.
Mission
● To provide quality education to meet the need of the society.
● Provide learning ambience to enhance innovations, problem solving skill,
leadership qualities, team spirit and ethical responsibility.
PEO
● The graduates will be able to meet the need of the society.
● The graduates will be able to design and establish software and to resolve various
technological problems.
The graduates will be able to develop professional skills which make ready them for
immediate employment and understand the need of lifelong learning for a
successful professional career.
Program outcomes
HARDWARE:
SOFTWARE:
COURSE OBJECTIVES
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and traceroute PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets.
3. Applications using TCP sockets like:
a) Echo client and echo server
b) Chat
c) File Transfer
4. Simulation of DNS using UDP sockets.
5. Write a code simulating ARP /RARP protocols.
6. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms
using NS.
7. Study of TCP/UDP performance using Simulation tool.
8. Simulation of Distance Vector/ Link State Routing algorithm.
9. Performance evaluation of Routing protocols using Simulation tool.
10. Simulation of error correction code (like CRC).
COURSE OUTCOMES:
[Cognitive Level K1- remember, K2- Understand, K3- Apply, K4 - Analyze, K5-
Evaluate, K6- Synthesize]
After successful completion of the course, the students should be able to
Highest
CO No. Course Outcomes Cognitive
Level
Title
Exp. No. Pg. No Signature
1
COMMANDS:
C:\>arp –a: ARP is short form of address resolution protocol, It will show the IP
address of your computer along with the IP address and MAC address of your router.
C:\>hostname: This is the simplest of all TCP/IP commands. It simply displays the
name of your computer.
C:\>ipconfig: The ipconfig command displays information about the host (the
computer your sitting at)computer TCP/IP configuration.
C:\>ipconfig /all: This command displays detailed configuration information about your
TCP/IP connection including Router, Gateway, DNS, DHCP, and type of Ethernet adapter
in your system.
C:\>Ipconfig /renew: Using this command will renew all your IP addresses that you are
currently (leasing) borrowing from the DHCP server. This command is a quick
problem solver if you are having connection issues, but does not work if you have been
configured with a static IP address.
C:\>Ipconifg /release: This command allows you to drop the IP lease from the DHCP
server.
C:\>ipconfig /flushdns: This command is only needed if you’re having trouble with
your networks DNS configuration. The best time to use this command is after network
configuration frustration sets in, and you really need the computer to reply with flushed.
C:\>nbtstat –a: This command helps solve problems with NetBIOS name resolution. (Nbt
stands for NetBIOS over TCP/IP)
C:\>nslookup: Nslookup is used for diagnosing DNS problems. If you can access a resource
by specifying an IP address but not it’s DNS you have a DNS problem.
C:\>ping: Ping is the most basic TCP/IP command, and it’s the same as placing a phone
call to your best friend. You pick up your telephone and dial a number, expecting your best
friend to reply with “Hello” on the other end. Computers make phone calls to each other
over a network by using a Ping command. The Ping commands main purpose is to place
a phone call to another computer on the network, and request an answer. Ping has 2 options
it can use to place a phone call to another computer on the network. It can use the
computers name or IP address.
C:\>route: The route command displays the computers routing table. A typical computer,
with a single network interface, connected to a LAN, with a router is fairly simple and
generally doesn’t pose any network problems. But if you’re having trouble accessing other
computers on your network, you can use the route command to make sure the entries in the
routing table are correct.
C:\>tracert: The tracert command displays a list of all the routers that a packet has to
go through to get from the computer where tracert is run to any other computer on the
internet.
RESULT:
Outcome:
Thus the student can know to implement networking comments using comments.
3
Application:
(1) IP routing
(2) Internet Control Message Protocol
Viva voce:
1) What is a Link?
4) What is a LAN?
5) What is a node?
4
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 getInputStream() 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:
Client2.java
import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Client2{
public static void main(String args[]) throws Exception{
Socket soc;
BufferedImage img = null;
soc=new Socket("localhost",4000);
System.out.println("Client is running. ");
try {
System.out.println("Reading image from disk. ");
img = ImageIO.read(new File("intel.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
5
Program:
Server2.java
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class Server2 {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept();
System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true);
}
}
6
Result:
Outcome:
Thus the student can know to implement C Program to download the file using HTTP.
Application:
Viva voce:
AIM
Server Side
1. Start the program.
2. Create a server socket to activate the port address.
3. Create a socket for the server socket which accepts the connection.
4. After establishing connection receive the data from client.
5. Print and send the same data to client.
6. Close the socket.
7. End the program.
Program
Echo Client
import java.io.*;
import java.net.*;
import java.util.*;
public class echoclient
{
public static void main(String args[])throws Exception
{
8
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
c=new Socket("127.0.0.1",5678);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{
}
if(c!=null || usr_inp!=null || dout!=null)
{
String unip;
while((unip=din.readLine())!=null)
{
dout.writeBytes(""+unip);
dout.writeBytes("\n");
System.out.println("\n the echoed message");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}
Program:
9
Echo Server:
import java.io.*;
import java.net.*;
public class echoserver
{
}
}
dout.close();
usr_inp.close();
c.close();
}
}
Result:
Outcome:
Thus the student can know to implement a socket program for implementation of
echo.
Application:
(1) Create data form server
Viva voce:
1. What are functions of different layers?
2. Differentiate between TCP/IP Layers and OSI Layers
3. Why header is required?
4. What is the use of adding header and trailer to frames?
.
11
AIM
To write a socket program for implementation of chat.
ALGORITHM
1. In any Client/Server Application, we need to 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.
Program
//talkclient.java
import java.io.*;
import java.net.*;
public class talkclient
{
public static void main(String args[])throws Exception
{
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
c=new Socket("127.0.0.1",1234);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
12
Program
//talkserver.java
import java.io.*;
import java.net.*;
public class talkserver
{
public static void main(String args[])throws Exception
{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
13
DataOutputStream dout=null;
try
{
m=new ServerSocket(1234);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
if(c!=null||usr_inp!=null)
{
String unip;
while(true)
{
System.out.println("\nmessage from client:");
String m1=usr_inp.readLine();
System.out.println(m1);
System.out.println("enter your message:");
unip=din.readLine();
dout.writeBytes(""+unip);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();
}}
Result:
14
Outcome:
Thus the student can know to implement a client-server application for chat using
TCP.
Application:
(1)Facebook
(2)Gmail
Viva voce:
1. What Are The Two Broad Classes Of Middleware In Client Server Environment?
2. What Are General Middleware In Client Server Environment?
3. What Are The Five Major Technologies That Can Be Used To Create Client/server
Applications In Client Server Environment?
4. What Are All The Base Services Provided By The Os In Client Server Environment?
5. What Are Super Servers In Client Server Environment?
15
AIM
To Perform File Transfer in Client & Server Using TCP/IP.
Algorithm:
Program:
Clientfile.java
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",9191);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
16
Program:
Serverfile.java
import java.io.*;
import java.net.*;
import java.util.*;
17
class Serverfile
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(9191);
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);}
}
}
18
RESULT:
Outcome:
Thus the student can know to implement File Transfer in Client & Server Using
TCP/IP.
Application:
(1) Terminals
Viva voce:
1. Can we create logs for ftp authenticated sessions ?
2. How to deny specific users access to the FTP server ?
3. Local users cannot log in. How to resolve this issue?
4. What is FTP ?
19
Ex No: 4 Program for Domain Name System (DNS) using UDP sockets
Aim:
To write a java program to simulate DNS using UDP sockets
Algorithm:
Server
1. Create two ports, server port and client port.
2. Create a datagram socket and bind it to client port.
3. Create a datagram packet to receive client message.
4. Wait for client's data and accept it.
5. Read Client's message.
6. Get data from user.
7. Create a datagram packet and send message through server port.
8. Repeat steps 3-7 until the client has something to send.
9. Close the server socket.
10. Stop.
Client
1. Create two ports, server port and client port.
2. Create a datagram socket and bind it to server port.
3. Get data from user.
4. Create a datagram packet and send data with server ip address and client port.
5. Create a datagram packet to receive server message.
6. Read server's response and display it.
7. Repeat steps 3-6 until there is some text to send.
8. Close the client socket.
9. Stop.
Program:
//Clientdns12.java
import java.io.*;
import java.net.*;
import java.util.*;
20
class Clientdns12
{
//Serverdns12.java
import java.io.*;
import java.net.*;
21
import java.util.*;
class Serverdns12
{
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);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String name[]={"www.aptitudeguru.com","www.downloadcyclone.blogspot.com"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(ip[i]))
{
sendbyte=name[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
else if(s.equals(name[i]))
{
22
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);
}
}
}
RESULT:
Outcome:
Thus the student can know to simulate DNS using UDP sockets.
Application:
1. Finding the ip address for the particular web address and vice verse.
Viva voce:
1. Explain udp.
2. List out common tcp/ip protocols
23
Ex No: 5(a) Program for Address Resolutuion Protocol (ARP) using UDP
Aim:
To write a java program for simulating ARP protocols using TCP
ALGORITHM:
Client
Server
//Clientarp12.java
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
System.out.println(e);
}
}
}
//Serverarp12.java
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp12
{
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);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
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(ip[i]))
{
sendbyte=mac[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Result:
25
Outcome:
Thus the student can know to write a java program to simulate address resolution protocol.
Application:
1. Masking
Viva voce:
1. Explain ARP.
2. To Which Osi Layer Does Arp Belong?
3. What Is The Use Of Arp?
26
Aim:
To write a java program for simulating RARP protocols using TCP
ALGORITHM:
Client
Server
// Clientrarp12.java
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));
27
// Serverrarp12.java
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)
{
28
Result:
Outcome:
Thus the student can know to write a java program to simulate reverse address resolution
protocol.
Application:
1Masking
Viva voce:
1.Explain RARP.
2.To Which Osi Layer Does Arp Belong?
3.What Is the Use Of Rarp?
30
AIM:
To simulate a link failure and observe the congestion control algorithm using NS2.
ALGORITHM:
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
31
$cbr1 attach-agent
$udp1 set null0
[new Agent/Null]
$ns attach-agent $n6 $null0
$ns connect $udp1
$null0 set udp2 [new
Agent/UDP]
$ns attach-agent $n0 $udp2
set cbr2 [new Application/Traffic/CBR]
$cbr2 set packet size_ 500
$cbr2 set interval_ 0.005
$cbr2 attach-agent
$udp2 set null0
[new Agent/Null]
$ns attach-agent $n7 $null0
$ns connect $udp2 $null0
$udp0 set fid_ 1
$udp1 set fid_ 2
$udp2 set fid_ 3
$ns color 1 Red
$ns color 2 Green
$ns color 2 Blue
$ns at 0.1 "$cbr0 start"
$ns at 0.2 "$cbr1 start"
$ns at 0.5 "$cbr2 start"
$ns at 4.0 "$cbr2 stop"
$ns at 4.2 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run
Result:
33
Outcome:
Thus the student can know congestion control algorithm is simulated by using NS2
Application:
1. Marketing
Viva voce:
1. What is the difference between physical topology and logical topology?
2. What is the Packet Sniffer?
34
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} {
35
RESULT:
Outcome:
Thus the student can know to write Distance vector Routing Algorithm
Application:
1. Mobile Nodes
Viva voce:
1. Compare connection oriented and connection less protocols.
2.What is MTU?
3.Explain the working of Distance vector routing.
4.Differentiate Proactive and Reactive routing Protocols.
5.What are the different attributes for calculating the cost of a path?
37
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 }
38
RESULT:
Outcome:
Thus the student can know to simulate and study the link state routing algorithm.
Application:
1. Connections between node
Viva Questions:
1. What is Routing?
2. What is Dynamic rouitng?
3. What are the two steps in link state routing?
4. Compare link state and Distance Vector routing
5. What are all the route metric used in Link state routing?