Computer Networks Lab File
Computer Networks Lab File
Computer Networks Lab File
TECHNOLOGY
Rooma, Kanpur (U.P.)
DEPARTMENT OF COMPUTER
SCIENCE AND ENGINEERING
(KCS-653)
3.
Study of network IP. 12/03/24 12/03/24
4. Configure a Network topology using
packet tracer software. 12/03/24 12/03/24
1. Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very
careful at this point, as to not nick or cut into the wires, which are inside. Doing so could alter
the characteristics of your cable, or even worse render is useless. Check the wires, one more
time for nicks or cuts. If there are any, just whack the whole end off, and start over.
2. Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand.
You do not want the wires to become untwisted down inside the jacket. Category 5 cable
must only have 1/2 of an inch of 'untwisted' wire at the end; otherwise it will be 'out of spec'.
At this point, you obviously have ALOT more than 1/2 of an inch of un-twisted wire.
3. You have 2 end jacks, which must be installed on your cable. If you are using a pre-made
cable, with one of the ends whacked off, you only have one end to install - the crossed over
end. Below are two diagrams, which show how you need to arrange the cables for each type
of cable end. Decide at this point which end you are making and examine the associated
picture below.
Diagram shows you how to prepare Cross wired connection
Diagram shows you how to prepare straight through wired connection
EXPERIMENT-02
Aim:- Study of following Network Devices in Detail:
• Repeater
• Hub
• Switch
• Bridge
• Router
• Gate Way
2. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator
is a device for connecting multiple twisted pair or fiber optic Ethernet devices together and
making them act as a single network segment. Hubs work at the physical layer (layer 1) of the
OSI model. The device is a form of multiport repeater. Repeater hubs also participate in
collision detection, forwarding a jam signal to all ports if it detects a collision.
4. Bridge: A network bridge connects multiple network segments at the data link layer
(Layer 2) of the OSI model. In Ethernet networks, the term bridge formally means a device
that behaves according to the IEEE 802.1D standard. A bridge and switch are very much
alike; a switch being a bridge with numerous ports. Switch or Layer 2 switch is often used
interchangeably with bridge.Bridges can analyze incoming data packets to determine if the
bridge is able to send the given packet to another segment of the network.
6. Gate Way: In a communications network, a network node equipped for interfacing with
another network that uses different protocols.
• A gateway may contain devices such as protocol translators, impedance matching
devices, rate converters, fault isolators, or signal translators as necessary to provide
system interoperability. It also requires the establishment of mutually acceptable
administrative procedures between both networks.
• A protocol translation/mapping gateway interconnects networks with different
network protocol technologies by performing the required protocol conversions.
EXPERIMENT- 03
• Classification of IP address
• Sub netting
• Super netting
Apparatus (Software): NA
As show in figure we teach how the ip addresses are classified and when they are used.
• Sub netting
Why we Develop sub netting and How to calculate subnet mask and how to identify subnet
address.
• Super netting
Why we develop super netting and How to calculate supernet mask and how to identify
supernet address.
EXPERIMENT-04
Aim: Configure a Network topology using packet tracer
software.
After configuring the given network a packet should be ping from any one machine to
another.
Router>
Router>Enable
Router#config t
Router(config)#hostname router0
router0(config-if)#no shutdown
router0(config-if)#exit
router0(config-if)#no shutdown
router0(config-if)#exit
router0(config)#exit
router0#show running-config
Building configuration...
version 12.4
no service password-encryption
hostname router0
ip ssh version 1
interface FastEthernet0/0
duplex auto
speed auto
interface FastEthernet0/1
no ip address
duplex auto
speed auto
interface Vlan1
no ip address
shutdown
ip classless
line con 0
line vty 0 4
login
end
router0#
router0#
Building configuration...
[OK]
router0#
EXPERIMENT- 05
Aim: Study of basic network command and Network configuration commands.
In this EXPERIMENT- students have to understand basic networking commands e.g ping,
tracert etc.
All commands related to Network configuration which includes how to switch to privilege
mode and normal mode and how to configure router interface and how to save this
configuration to flash memory or permanent memory.
ping:
ping(8) sends an ICMP ECHO_REQUEST packet to the specified host. If the host responds,
you get an ICMP packet back. Sound strange? Well, you can “ping” an IP address to see if a
machine is alive. If there is no response, you know something is wrong.
Traceroute:
Tracert is a command which can show you the path a packet of information takes from your
computer to one you specify. It will list all the routers it passes through until it reaches its
destination, or fails to and is discarded. In addition to this, it will tell you how long each 'hop'
from router to router takes.
nslookup:
pathping:
A better version of tracert that gives you statics about packet lost and latency.
Getting Help
In any command mode, you can get a list of available commands by entering a question mark (?).
Router>?
To obtain a list of commands that begin with a particular character sequence, type in those
haracters followed immediately by the question mark (?).
Router#co?
Router#configure ?
Configuration Files
Any time you make changes to the router configuration, you must save the changes to memory
because if you do not they will be lost if there is a system reload or power outage. There are two
types of configuration files: the running (current operating) configuration and the startup
configuration.
Use the following privileged mode commands to work with configuration files.
• configure terminal – modify the running configuration manually from the terminal.
IP Address Configuration
Router>enable password
Step 2: Enter the configure terminal command to enter global configuration mode.
Router#config terminal
Step 3: Enter the interface type slot/port (for Cisco 7000 series) or interface type port (for Cisco
2500 series) to enter the interface configuration mode.
Example:
Router (config)#interface ethernet 0/1
Step 4: Enter the IP address and subnet mask of the interface using the ip address ipaddress
subnetmask command.
Example,
Router (config-if)#ip address 192.168.10.1 255.255.255.0
if(nf<=sws-1)
{
System.out.println("Enter "+nf+" Messages to be send\n");
for(i=1;i<=nf;i++)
{
sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8;
}
sws-=nf;
System.out.print("Acknowledgment received");
ano=Integer.parseInt(in1.readLine());
System.out.println(" for "+ano+" frames");
sws+=nf;
}
else
{
System.out.println("The no. of frames exceeds window
size"); break;
}
System.out.print("\nDo you wants to send some more frames : ");
ch=in.readLine(); p.println(ch);
}
while(ch.equals("yes"));
s.close();
}
}
RECEIVER PROGRAM
import java.net.*;
import java.io.*;
class slidreceiver
{
public static void main(String a[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10);
DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
int i=0,rptr=-1,nf,rws=8;
String rbuf[]=new String[8];
String ch; System.out.println();
do
{
nf=Integer.parseInt(in.readLine())i
f(nf<=rws-1)
{
for(i=1;i<=nf;i++)
{
rptr=++rptr%8;
rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
}
rws-=nf;
System.out.println("\nAcknowledgment
sent\n"); p.println(rptr+1); rws+=nf; }
else
break;
ch=in.readLine();
}
while(ch.equals("yes"));
}
}
OUTPUT:
//SENDER OUTPUT
Enter the no. of frames : 4
Enter 4 Messages to be send
hiii
how r u
i am fine
how is evryone
Acknowledgment received for 4 frames
Do you wants to send some more frames : no
//RECEIVER OUTPUT
The received Frame 0 is : hiii
The received Frame 1 is : how r u
The received Frame 2 is : i am fine
The received Frame 3 is : how is everyone
RESULT:
Thus the program for implementing stop and wait protocol and
sliding window protocol was executed successfully.
EXPERIMENT-07
AIM:
To implement socket programming date and time display from client to server using TCP
Sockets
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 server‟s date and time to the client.
4. Read client‟s 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:
//TCP Date Server--tcpdateserver.java
import java.net.*;
import java.io.*;
import java.util.*;
class tcpdateserver
{
public static void main(String arg[])
{
ServerSocket ss = null;
Socket cs; PrintStream ps;
BufferedReader dis;
String inet; try
{
ss = new ServerSocket(4444);
System.out.println("Press Ctrl+C to quit"); while(true)
{
cs = ss.accept();
ps = new PrintStream(cs.getOutputStream());
Date d = new
Date() ps.println(d);
dis = new BufferedReader(new InputStreamReader(cs.getInputStream()));
inet = dis.readLine(); System.out.println("Client System/IP address is :"+
inet); ps.close(); dis.close();
}
}
catch(IOException e)
{ System.out.println("The exception is :" + e);
}
}
}
// TCP Date Client--tcpdateclient.java
import java.net.*;
import java.io.*;
class tcpdateclient
{
public static void main (String args[])
{ Socket soc; BufferedReader dis;
String sdate; PrintStream ps;
try { InetAddress ia =
InetAddress.getLocalHost(); if (args.length == 0)
soc = new Socket(InetAddress.getLocalHost(),4444);
else soc = new Socket(InetAddress.getByName(args[0]),4444);
dis = new BufferedReader(new InputStreamReader(soc.getInputStream()));
sdate=dis.readLine(); System.out.println("The date/time on server is : "
+sdate); ps = new PrintStream(soc.getOutputStream());
ps.println(ia);
ps.close();
catch(IOException e)
{
System.out.println("THE EXCEPTION is :" + e);
}
}
}
OUTPUT
$ javac tcpdateserver.java
$ java tcpdateserver
Press Ctrl+C to quit Client System/IP address is : localhost.localdomain/127.0.0.1
Client System/IP address is : localhost.localdomain/127.0.0.1
Client: $
javac tcpdateclient.java $ java tcpdateclient The date/time on server is: Wed Jul 06
07:12:03 GMT 2011
Every time when a client connects to the server, server‟s date/time will be returned to the
client for synchronization.
RESULT:
Thus the program for implementing to display date and time from client to server
using TCP Sockets was executed successfully and output verified using various samples.
EXPERIMENT- 08
Aim:
To write a java program for simulating arp/rarp protocols
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 server‟s date and time to the client.
4. Read client‟s 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);
}
}
}
Output:
E:\networks>java Serverarp
E:\networks>java Clientarp
Enter the Logical
address(IP): 165.165.80.80
The Physical Address is: 6A:08:AA:C2
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);
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(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);
}
}
}
Output:
I:\ex>java Serverrarp12
I:\ex>java Clientrarp12
Enter the Physical address (MAC):
6A:08:AA:C2
The Logical Address is(IP): 165.165.80.80
Result :
Thus the program for implementing to display simulating ARP /RARP protocols.
EXPERIMENT- 09
Aim:
To Write The java program for simulating ping and traceroute commands
ALGORITHM:
1. Start the program.
2. Get the frame size from the user
3. To create the frame based on the user request.
4. To send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will
send NACK signal to client.
6. Stop the program
Program
//pingclient.java
import java.io.*;
import java.net.*;
import java.util.Calendar;
class pingclient
{
public static void main(String args[])throws Exception
{
String str;
int c=0;
long t1,t2;
Socket s=new Socket("127.0.0.1",5555);
DataInputStream dis=new DataInputStream(s.getInputStream());
PrintStream out=new PrintStream(s.getOutputStream());
while(c<4)
{
t1=System.currentTimeMillis();
str="Welcome to network programming world";
out.println(str);
System.out.println(dis.readLine());
t2=System.currentTimeMillis();
System.out.println(";TTL="+(t2-t1)+"ms");
c++;
}
s.close();
}
}
//pingserver.java
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
class pingserver
{
public static void main(String args[])throws Exception
{
ServerSocket ss=new
ServerSocket(5555); Socket s=ss.accept();
int c=0;
while(c<4)
{
DataInputStream dis=new DataInputStream(s.getInputStream());
PrintStream out=new PrintStream(s.getOutputStream());
String str=dis.readLine();
out.println("Reply
from"+InetAddress.getLocalHost()+";Length"+str.length()); c++;
}
s.close();
}
}
Output :
Result:
Thus the program was implementing to simulating ping and traceroute commands
Experiment -10
Aim:-
To write a java program to implement RPC (remote procedure call
Algorithm :
1. Start the program.
2. Get the frame size from the user
3. To create the frame based on the user request.
4. To send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will
send NACK signal to client.
6. Stop the program
Program:-
RPC PROGRAM
Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrpc
{
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
String"); String str=in.readLine();
dout.writeBytes(str+'\n');
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Server
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrpc
{
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();
Process p=Runtime.getRuntime().exec(str);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT
Server
Y:\networks\remote>java
Serverrpc Client
Y:\networks\remote>java
Clientrpc Enter String
calc
Result :
Thus the program was implementing to implement RPC (remote procedure call