CN Lab Manual (2024-25)
CN Lab Manual (2024-25)
LAB MANUAL
Computer Networks Lab
(Course Code: BCS-653)
PROGRAM:
B. TECH. (CSE)-VI SEMESTER (2024-25)
SYLLABUS AS PER
Dr. A. P. J. ABDUL KALAM TECHNICAL UNIVERSITY, LUCKNOW
Session: 2024-25
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 1 of 44
INDEX
S.No Contents
1. Vision & Mission of the Institute & Department
2. Prescribed University Syllabus
3. List of Experiments/ LAB Plan
4. Course Outcome
5. CO-PO-PSO Mapping
6. Lab Manuals
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 2 of 44
IIMT COLLEGE OF ENGINEERING,
GREATER NOIDA
(Department of Computer Science & Engineering)
---------------------------------------------------------------------------------------------------------------------
To be among the renowned institutions providing engineering and management education of excellence,
empowered with research, innovation and entrepreneurship with high ethical values, catering to the needs
of industry and society.
To produce globally competent Computer Science engineers empowered with research aptitude and high
ethical values to cater to the emerging computing needs of the industry and society.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 3 of 44
➢ To develop strong industry –academia relationship.
➢ To nurture students and infuse professional ethics, human values and positive attitude in the stu-
dents.
---------------------------------------------------------------------------------------------------------------------
PEO 1: To provide solid foundation in computer science engineering along with good communication
and entrepreneurship skills for tackling social issues.
PEO 2: To impart students with good scientific and engineering knowledge in order to analyze, design
and create novel products for giving practical solutions to real life problems.
PEO 3: To create engineers with sound technical knowledge for facing all sorts of challenges in industry
or in pursuance of higher studies.
PEO 4: To motivate students acquire aptitude for lifelong learning along with leadership skills, team
spirit and ethical values.
PSO 1: Ability to interpret and analyze network issues in real world environment.
PSO 2: Ability to design and develop web and mobile based application under realistic constraints.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 4 of 44
IIMT COLLEGE OF ENGINEERING,
GREATER NOIDA
(Department of Computer Science & Engineering)
---------------------------------------------------------------------------------------------------------------------
PO2-Problem Analysis: Identify, Formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
PO3-Design/Development of Solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO5-Modern Tool Usage: Create, Select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6-The Engineer and Society: Apply Reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 5 of 44
PO7-Environment and Sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8-Ethics: Apply Ethical Principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
PO9-Individual and Team Work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings
PO12-Life-Long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 6 of 44
(Computer Science &Engineering Department)
Lab Plan
Teacher: MR BADAL BHUSHAN File Name: LP-BCS653
Course Outcome:
1. To expose students for designing straight cable, cross cable, detect error and correct those error in the
frame.
2. To develop ability for rotating which is used to find best path of packet
Learning Outcome:
1. Identify the error in a frame and correct those error in that frame.
2. Understanding concept of finding best path of packet from source to destination using routing
3. LIST OF EXPERIMENTS
1. 1. Study of different network devices (Hub, Switch, Router, and Gateway) in detail.
3. 3. Design a LAN having 10 computers and connect them using Switch using start
topology. Simulate your work using CISCO Packet tracer
4. 4. Design a network having two LAN connected via a Router? Configure the router
using CISCO Packet Tracer
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 7 of 44
5. 5. Implementation of Stop and Wait Protocol and Sliding Window Protocol.
9. 9.
Configuring WEP on a Wireless Router
10. 10.
Program for Reverse Address Resolution Protocol (RARP) using UDP
G1, G2 both the batches will do the same assignment on one tern. The lab is
• Basic concept of problems shall be discussed first in the lab then the coding
of program using C language and packet routing on Cisco packet tracer software will be done.
• Students are supposed to maintain a lab file of all the programs along with
outputs.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 8 of 44
DO’S AND DONT’S DO’s
DONT’S
1. Know the location of the fire extinguisher and the first aid box and how to use them
in case of an emergency.
2. Report fires or accidents to your faculty /laboratory technician immediately.
3. Report any broken plugs or exposed electrical wires to your faculty/laboratory tech-
nician immediately.
4. Do not plug in external devices without scanning them for computer viruses
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 9 of 44
(Department of Computer Science and Engineering)
Course Name: Computer Networks Lab; Course Code: (BCS-653)
LIST OF EXPERIMENTS
SL NAME OF EXPERIMENT
Study of different network devices (Hub, Switch, Router, and Gateway) in de-
1
tail.
Study of handling and configuration of networking hardware like RJ-45 Con-
2
nector, CAT-6 Cable, crimping tools, and LAN tester.
Design a LAN having 10 computers and connect them using Switch using
3
start topology. Simulate your work using CISCO Packet tracer
Design a network having two LAN connected via a Router? Configure the
4
router using CISCO Packet Tracer
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 10 of 44
EXPERIMENT NO. 1
Name of Experiment: Study of different network devices (Hub, Switch, Router, and Gateway)
in detail.
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Objective:
To study different network devices (Hub, Switch, Router, and Gateway) in detail.
Resource Requirement:
H/W Requirements: Network devices such as hubs, switches, routers, and gateways for hands-on learning,
network cables to connect the device.
S/W Requirements: Cisco Packet Tracer.
Theory:
Hub:
A hub is a basic networking device that connects multiple devices in a network. It operates on the physical layer of
the OSI model and is responsible for simply repeating any incoming signal it receives to all the other devices
connected to it, regardless of whether the intended recipient is present. Hubs are now outdated and have been largely
replaced by switches. This is because hubs are prone to collisions, which can cause significant network congestion.
Figure 1 : Hub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 11 of 44
Switch: A switch is a networking device that operates on the data link layer of the OSI model. It is designed to
connect multiple devices in a network and selectively forward data packets to their intended destinations based on
the MAC addresses of the devices. Switches provide a more efficient and secure way of transferring data compared
to hubs. This is because switches create a dedicated path between the source and destination devices, reducing
network congestion and preventing data collisions.
Figure 2: Switch
Router:
A router is a networking device that operates on the network layer of the OSI model. It is responsible for forwarding
data packets between different networks or subnets based on the IP addresses of the devices. Routers can connect
different types of networks, including LANs, WANs, and the internet. They can also perform functions such as
network address translation (NAT) and firewalling, which help to protect the network from unauthorized access
and attacks.
Figure 3: Router
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 12 of 44
Gateway:
A gateway is a networking device that serves as the entry or exit point for a network. It can connect different types
of networks that use different communication protocols, allowing them to communicate with each other. For
example, a gateway can connect a LAN to the internet, translating between the protocols used by the LAN and the
internet. Gateways can also perform functions such as routing, filtering, and protocol conversion.
Figure 4: Gateway
Conclusion: In conclusion, studying different network devices such as hubs, switches, routers, and gateways is
critical for building and maintaining effective network.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 13 of 44
EXPERIMENT NO. 2
Name of Experiment: Study of handling and configuration of networking hardware like RJ-
45 connector, CAT-6 cable, crimping tool, and LAN tester.
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Objective: To study handling and configuration of networking hardware like RJ-45 connector, CAT-6
cable, crimping tool, and LAN tester.
Resource Requirement:
H/W Requirements: RJ45, CAT cables, Crimping Tool, Printer, and Internet Connection.
S/W Requirements: Cisco Packet Tracer.
Theory: RJ-45 connector: RJ45 cable is used for connecting the ALL HMI and engineer station through a switch
to communicate with each other. It is used to download the any modification, and which is made in graphics in
engineering station. RJ45 cable is also used for communicating the printer with computer. There are four pairs of
wires in an Ethernet cable, and an Ethernet connector (8P8C) has eight pin slots. Each pin is identified by a number,
starting from left to right, with the clip facing away from you.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 14 of 44
Straight Through Cable: Straight Through Ethernet cables are the standard cable used for almost all purposes and
are often called “patch cables”. It is highly recommended you duplicate the color order as shown on the left. Note
how the green pair is not side-by- side as are all the other pairs. This configuration allows for longer wire runs
Crossover Cable: The purpose of a Crossover Ethernet cable is to directly connect one computer to another
computer (or device) without going through a router, switch, or hub.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 15 of 44
CAT Cables: The Cat, as you might know, is short for "Category." The term "Category" refers to the different
levels of performance in signal bandwidth, attenuation and crosstalk associated with each cable's design.
Category 1 cables are a 2-pair copper UTP designed for POTS (plain old telephone systems). CAT 5e is currently
the most used cable, mainly due to its low production cost and support for speeds faster than Cat 5 cables. A Cat6
cable has a bandwidth capacity of 250 MHz, for example, and it offers you speeds of up to 10 Gbps. It's also
compatible with both Cat5 and Cat5E cables. “A Cat6 cable is used mainly for computer networks reaching a GB,
1000 Mbps or one Gbps of data transfer speed (DTR) or higher,”
A Cat6 cable has a bandwidth capacity of 250 MHz, for example, and it offers you speeds of up to 10 Gbps. It's
also compatible with both Cat5 and Cat5E cables. “A Cat6 cable is used mainly for computer networks reaching a
GB, 1000 Mbps or one Gbps of data transfer speed (DTR) or higher,”.
Crimping Tool:
Crimpers are tools used to make cold weld joints between two wires or a wire and a connector, such as lugs. Ideally,
the electrical and mechanical properties of the weld joint are as strong as the parent materials. Crimping tools are
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 16 of 44
sized according to the wire gauges (using AWG - American Wire Gauge) they can accept. Some come with
interchangeable die heads that allow for a wider range of wire sizes and connectors
How to use:
First you will need to strip the length of wire that you want to crimp. Then, attach the connector. For crimping tools
with interchangeable dies, you will need to select the right die head for the connector by matching wire gauge
ratings. For die less crimpers, you will need to match to the proper groove. Finally, apply pressure, take out the
newly crimped connector, and give a few tugs to make sure you have a solid and secure connection.
LAN tester:
A LAN tester is an essential tool for any computer network lab to ensure that the LAN is functioning correctly and
to troubleshoot any problems that may arise.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 18 of 44
EXPERIMENT NO. 3
Name of Experiment: Design a LAN having 10 computers and connect them using
Switch using start topology. Simulate your work using CISCO Packet tracer
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Objective:
To design a LAN having 10 computers and connect them using a switch using star topology. The experiment will
be simulated using Cisco Packet Tracer.
Apparatus (Software) Requirement: Cisco Packet Tracer.
Procedure: The steps involved in the experiment are as follows:
Step 1: Open Cisco Packet Tracer. To open Cisco Packet Tracer, go to the Start menu and search for "Packet
Tracer". Click on the Cisco Packet Tracer icon to open the application.
Step 2: Create a new project. To create a new project, click on the "File" menu and select "New Project". In the
"New Project" dialog box, enter a name for your project and click on the "Create" button
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 19 of 44
Step 3: Add a switch to the project. To add a switch to the project, click on the "Devices" menu and select "Add >
Switch". In the "Add Switch" dialog box, select the type of switch you want to add and click on the "Add" button.
Step 4: Connect 10 computers to the switch using Ethernet cables. To connect 10 computers to the switch using
Ethernet cables, click on the "Devices" menu and select "Add > PC". In the "Add PC" dialog box, select the type
of PC you want to add and click on the "Add" button. Repeat this step 9 more times to add 10 PCs to the project.
Once you have added 10 PCs to the project, connect each PC to the switch using an Ethernet cable. To do this, drag
the Ethernet cable from the PC to the switch port
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 20 of 44
Step 5: Configure the IP addresses of the computers. To configure the IP addresses of the computers, click on the
"Config" tab of the PC's properties window. In the "IP Address" field, enter the IP address of the PC. In the "Subnet
Mask" field, enter the subnet mask for the network. Repeat this step for all 10 PCs
Figure 4 : IP Configuration
Step 6: Test the connectivity between the computers by pinging each computer from another computer. To test the
connectivity between the computers, open a command prompt on one of the computers. In the command prompt,
type "ping" followed by the IP address of another computer. If the computer is reachable, you will see a response
message. Repeat this step for all 10 computers.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 21 of 44
Figure 5 : Testing Connectivity
Finally, we should now have a LAN with 10 computers connected to a switch using star topology in Cisco Packet
Tracer. We can verify this by opening the Topology window, where we should see all 10 computers connected to
the switch.
Conclusion: In conclusion, the experiment was a success. The 10 computers were successfully connected to the
switch using star topology in Cisco Packet Tracer. The connectivity between the computers was also verified by
pinging each computer from another computer. This experiment has demonstrated that star topology is a reliable
and efficient way to connect computers in a LAN. It is also a very scalable topology, as it can be easily expanded
by adding more computers.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 22 of 44
EXPERIMENT NO. 4
Name of Experiment: Design a network having two LAN connected via a Router? Configure the
router using CISCO Packet Tracer
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Objective:
To design a network with two LANs connected via a router and configure the router using Cisco Packet Tracer.
Apparatus Requirement: Cisco Packet Tracer software, Two switches, Four PCs, Ethernet cables.
Procedure:
Step 1: Open Cisco Packet Tracer and create a network with two switches.
o Launch Cisco Packet Tracer.
o Drag and drop two switches onto the workspace.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 23 of 44
Figure 2 : Assigning IP
Step 3: Establish connections between the two switches using a router. o Drag and drop a router onto the workspace.
o Connect the LAN-1 switch's interface (e.g., GigabitEthernet0/1) to one of the router's interfaces (e.g.,
GigabitEthernet0/0). o Connect the LAN-2 switch's interface (e.g., GigabitEthernet0/1) to another interface on the
router (e.g., GigabitEthernet0/1).
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 24 of 44
Step 4: Configure the router. Double-click on the router to open the configuration dialog box. Click on the "CLI"
(Command Line Interface) tab to access the router's command line interface
Step 5: Configure the router interfaces. Enter the following commands to configure the interfaces of the router
Step 7: Test the connection. Open a command prompt on each PC and try to ping the IP address of the other PC.
For example, on PC1, enter the following command:
Step 7: Test the connection. Open a command prompt on each PC and try to ping the IP address of the
other PC. For example, on PC1, enter the following command:
ping 10. 10. 10. 10. 3
Result: The pings are successful; it means that the two LANs are connected via the router.
Conclusion: We have successfully designed a network with two LANs connected via a router using Cisco
Packet Tracer and tested the connectivity between the PCs.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 25 of 44
EXPERIMENT NO. 5
Name of Experiment: Implementation of Stop and Wait Protocol and Sliding Window
Protocol.
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
It is the simplest flow control method. In this, the sender will transmit one frame at a time to the receiver. The
sender will stop and wait for the acknowledgement from the receiver.
This time (i.e. the time joining message transmitting and acknowledgement receiving) is the sender’s waiting time,
and the sender is idle during this time.
When the sender gets the acknowledgement (ACK), it will send the next data packet to the receiver and wait for
the disclosure again, and this process will continue as long as the sender has the data to send.
While sending the data from the sender to the receiver, the data flow needs to be controlled. If the sender is trans-
mitting the data at a rate higher than the receiver can receive and process it, the data will get lost.
The Flow-control methods will help in ensuring that the data doesn't get lost. The flow control method will check
that the senders send the data only at a rate that the receiver can receive and process.
1. Error correction in Stop-and-Wait ARQ is done by keeping a copy of the sent frame and retransmitting of
the frame when the timer expires.
2. In Stop-and-Wait ARQ, we use sequence numbers to number the frames. The sequence numbers are based
on modulo-2 arithmetic
3. In Stop-and-Wait ARQ, the acknowledgment number always announces in modulo-2 arithmetic the se-
quence number of the next frame expected.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 26 of 44
The working of Stop and Wait Protocol is shown in the figure below −
Shows an example of Stop-and-Wait ARQ. Frame 0 is sent and acknowledged. Frame 1 is lost and resent after
the time-out. The resent frame 1 is acknowledged and the timer stops. Frame 0 is sent and acknowledged, but
the acknowledgment is lost. The sender has no idea if the frame or the acknowledgment is lost, so after the time-
out, it resends frame 0, which is acknowledged.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 27 of 44
Sliding Window Protocol in Computer Network
Sliding window protocols are data link layer protocols for reliable and sequential delivery of data frames. The
sliding window is also used in Transmission Control Protocol.
In this protocol, multiple frames can be sent by a sender at a time before receiving an acknowledgment from the
receiver. The term sliding window refers to the imaginary boxes to hold frames. Sliding window method is also
known as windowing
Program in Java
Sender.java
import java.io.*;
import java.net.*;
public class Sender{
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,str, msg;
int n,i=0,sequence=0;
Sender(){}
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 28 of 44
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Waiting for Connection....");
sender = new Socket("localhost",2005);
sequence=0;
out=new ObjectOutputStream(sender.getOutputStream());
out.flush();
in=new ObjectInputStream(sender.getInputStream());
str=(String)in.readObject();
System.out.println("reciver > "+str);
System.out.println("Enter the data to send....");
packet=br.readLine();
n=packet.length();
do{
try{
if(i<n){
msg=String.valueOf(sequence);
msg=msg.concat(packet.substring(i,i+1));
}else if(i==n){
msg="end";out.writeObject(msg);break;
}out.writeObject(msg);
sequence=(sequence==0)?1:0;
out.flush();
System.out.println("data sent>"+msg);
ack=(String)in.readObject();
System.out.println("waiting for ack.....\n\n");
if(ack.equals(String.valueOf(sequence))){
i++;
System.out.println("receiver > "+" packet recieved\n\n");
}else{
System.out.println("Time out resending data....\n\n");
sequence=(sequence==0)?1:0;
}}catch(Exception e){}
}while(i<n+1);
System.out.println("All data sent. exiting.");
}catch(Exception e){}
finally{
try{
in.close();
out.close();
sender.close();
}
catch(Exception e){}
}}
public static void main(String args[]){
Sender s=new Sender();
s.run();
}}
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 29 of 44
Receiver.java
import java.io.*;
import java.net.*;
public class Receiver{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Receiver(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2005,10);
System.out.println("waiting for connection...");
connection=reciever.accept();
sequence=0;
System.out.println("Connection established :");
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected .");
do{
try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){
data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver >"+packet);
}
else
{
System.out.println("\n\nreceiver >"+packet +" duplicate data");
}if(i<3){
out.writeObject(String.valueOf(sequence));i++;
}else{
out.writeObject(String.valueOf((sequence+1)%2));
i=0;
}}
catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
out.writeObject("connection ended .");
}catch(Exception e){}
finally{
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 30 of 44
try{in.close();
out.close();
reciever.close();
}
catch(Exception e){}
}}
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 31 of 44
EXPERIMENT NO. 6
Name of Experiment: Study of Socket Programming and Client – Server model
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
AIM: To conduct an experiment to demonstrate the working of file transfer with the UDP Server and
Client.
The client–server model of computing is a distributed application structure that partitions tasks or workloads
between the providers of a resource or service, called servers, and service requesters, called clients. Often clients
and servers communicate over a computer network on separate hardware, but both client and server may reside in
the same system. A server host runs one or more server programs which share their resources with clients. A client
does not share any of its resources, but requests a server's content or service function. Clients therefore initiate
communication sessions with servers which await incoming requests.
PROCEDURE: In main window, enter Cd network, Cd layer, Cd Phy_Lyr , ./main Choose Layers - Transport
Layer - Socket - UDP. After choosing UDP protocol, Click on “Let’s Begin” button on both the systems. To start
the server, click on the Server Socket. Click on the Bind button, which will bind the socket. To start the Client,
first enter the IP Address of a machine where the server is listening. Enter the file name as a request as shown in
Screen. Click on socket to initiate the client socket. Click on the bind option. Click on the Send To button
to write the request. Click on the Recv From button, which will be highlighted upon receiving a request in server
system. Click on the Send To button to write the file contents in the server system. Click on Recv From button
in the client system to read the contents of the file. Observe the text for the output of the file as shown in Screen.
RESULT: Thus, the working of Client – Server Model concept was understood and output was verified
Java Programming:
Client-Side Program:
package Networking;
import java.net.*;
import java.io.*;
public class MyClient {
public static void main(String[] args) {
System.out.println("This is my Client Site program");
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 32 of 44
try {
Socket soc = new Socket("localhost",6666);
ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
out.writeUTF("Hello Server");
out.flush();
out.close();
soc.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
Server-Side Program:
package Networking;
import java.net.*;
import java.io.*;
public class MyServer {
public static void main(String[] args) {
System.out.println("This is my Server Site program");
try {
ServerSocket sos = new ServerSocket(6666);
Socket soc = sos.accept();
ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
String str = (String)ois.readUTF();
System.out.println("Message ="+str);
sos.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT:
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 33 of 44
EXPERIMENT NO. 7
Name of Experiment: Write a code simulating ARP /RARP protocols.
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Aim: To write a java program for simulating ARP protocols using TCP
ALGORITHM:
Client
1. Start the program
2. Using socket connection is established between client and server.
3. Get the IP address to be converted into MAC address.
4. Send this IP address to server.
5. Server returns the MAC address to client.
Server
1. Start the program
2. Accept the socket which is created by the client.
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the IP address which is send by the client.
5. Map the IP address with its MAC address and return the MAC address to client.
Program 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",5604);
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();
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 34 of 44
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(5604);
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
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 35 of 44
EXPERIMENT NO. 8
Name of Experiment: Write a code simulating PING and TRACEROUTE
commands
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Aim:
Algorithm
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 36 of 44
Program:
import java.io.*;
import java.net.*;
class pingserver
{
public static void main(String args[])
{
try
{
String str;
System.out.print(" Enter the IP Address to be Ping : ");
BufferedReader buf1=new BufferedReader(new
InputStreamReader(System.in));
String ip=buf1.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("ping " + ip);
InputStream in=p.getInputStream();
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
while((str=buf2.readLine())!=null)
{
System.out.println(" " + str);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Output:
Enter the IP address to the ping:192.168.0.1
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 37 of 44
ms,maximum=4ms,average=2ms
TRACEROUTE commands-
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class traceroutecmd
{
public static void runSystemCommand(String command)
{
try
{
Process p = Runtime.getRuntime().exec(command);
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String s = "";
while ((s = inputStream.readLine()) != null)
System.out.println(s);
}
catch (Exception e)
{
}
}
public static void main(String[] args)
{
// String ip = "www.google.co.in";
// String ip = "127.0.0.1";
String ip = "www.cp-algorithms.com";
runSystemCommand("tracert " + ip);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 38 of 44
EXPERIMENT NO. 9
Name of Experiment: Configuring WEP on a Wireless Router
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Objectives:
Configure WEP security between a workstation and a Linksys wireless router.
Background / Preparation:
You have been asked to go back to a business customer and install a new Linksys wireless
router for the customer office. The company has some new personnel who will be using
wireless computers to save money on adding additional wired connections to the building.
The business is concerned about the security of the network because they have financial
and highly classified data being transmitted over the network. Your job is to configure the
security on the router to protect the data.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 39 of 44
Topology Diagram
In this activity, you will configure WEP security on both a Linksys wireless router and a workstation.
a) Click the Customer Wireless Router icon. Then, click the GUI tab to access the router web
management interface.
b) Click the Wireless menu option and change the Network Name (SSID) from Default to Customer
Wireless. Leave the other settings with their default options.
c) Click the Save Settings button at the bottom of the Basic Wireless Settings window.
d) Click the Wireless Security submenu under the Wireless menu to display the current wireless
security parameters.
e) From the Security Mode drop-down menu, select WEP.
f) In the Key1 text box, type 1a2b3c4d5e. This will be the new WEP pre-shared key to access the
wireless network.
g) Click the Save Settings button at the bottom of the Wireless Security window.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 40 of 44
a) Click the Customer Wireless Workstation.
b) Click the Config tab.
c) Click the Wireless button to display the current wireless configuration settings on the workstation.
d) Change the SSID to Customer Wireless.
e) Change the Security Mode to WEP. Enter 1a2b3c4d5e in the Key text box, and then close the
window.
After you configure the correct WEP key and SSID on the customer wireless workstation, notice that there
is a wireless connection between the workstation and the wireless router.
a) Click the Customer Wireless Workstation.
b) Click the Desktop tab to view the applications that are available.
c) Click on the Command Prompt application to bring up the command prompt.
d) Type ipconfig /all and press Enter to view the current network configuration settings.
e) Type ping 192.168.2.1 to verify connectivity to the LAN interface of the customer wireless router.
f) Close the command prompt window.
g) Open a web browser.
h) In the address bar of the web browser window, type http://192.168.1.10. Press Enter. The Intranet
web page that is running on the customer server appears. You have just verified that the customer
wireless workstation has connectivity to the rest of the customer network.
Reflection
a) Click the Check Results button at the bottom of this instruction window to check your work. What
is the purpose of using WEP on a wireless network?
b) What is the significance of the key that you used to secure WEP?
c) Is WEP the best choice for wireless secure.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 41 of 44
EXPERIMENT NO. 10
Name of Experiment: Program for Reverse Address Resolution Protocol (RARP) using UDP
Course Name: Computer Networks Lab Course Code: BCS-653
Branch: CSE Semester: VI
Aim:
ALGORITHM:
Client
Server
Client:
try
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 42 of 44
{
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length); client.receive(receiver);
catch(Exception e)
System.out.println(e);
}
}
}
Server:
try
{
-----------------------------------------------------------------------------------------------------------------------------------------------------
Prepared by
Mr. Badal Bhushan, Assistant Professor, Department of CSE, IIMT College of Engineering, Greater Noida
Page 43 of 44
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
if(s.equals(mac[i]))
sendbyte=ip[i].getBytes();
DatagramPacket sender=newDatagramPacket(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