0% found this document useful (0 votes)
3 views24 pages

Program

Uploaded by

h9219sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views24 pages

Program

Uploaded by

h9219sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Networks Lab

BCS 653

PRACTICAL – 1
Date: 06-02-2026

Objective: To Study different network devices (Hub, Switch, Router and Gateway) in
detail.

Hub :- Hubs are intermediary devices that usually operate at the physical layer (Layer I) of the
OSI model that connect multiple devices on a local network. Hubs function by broadcasting
data to all the devices that are connected to it, regardless of their destination. Hubs can help in
simplifying the wiring and installation of a LAN by providing a central point of connection.
Hubs are capable of creating a single collision domain and a single broadcast domain.

Figure 1:- Hub

Switch :- Switches serve as networking devices that function at the data link layer (layer 2) of
the OSI model. The main purpose of switches is to connect end devices within a network and
allow the forwarding of data packets utilizing their MAC addresses. By creating collision
domains for each port, switches effectively mitigate collisions and congestion on the network.
Additionally, switches are capable of configuring VLANs (Virtual LANs) to establish logical
groups of devices on a network.

Figure 2:- Switch

2304221520025 1
Computer Networks Lab
BCS 653

Router :- Router are also networking devices that operate at the network layer (layer 3) of the
OSI model. The main function of the router is to connect networks and allow the forwarding
of data packets based on their respective IP addresses. By creating broadcast domains for each
interface, routers effectively reduce broadcast traffic on the network.

Figure 3:- Router

Gateway :- Gateways are intermediary devices that usually operate at the network layer (Layer
3) of the OSI model and are responsible for connecting networks that are using different
protocols or architectures. They do so by translating or converting data formats or protocols
between different networks. A gateway is one of the important networking devices as it acts as
a crucial component of any network architecture that involves multiple networks. Apart from
this, Gateways can carry out various other functions such as filtering, security, routing, and
encryption.

Figure 4:- Gateway

2304221520025 2
Computer Networks Lab
BCS 653

PRACTICAL – 2
Date: 13-02-2026

Objective: To learn the use and handling of networking devices such as RJ-CAT-6 cable
tool, and LAN tester.

1. RJ-45 Connector: An RJ-45 connector is a standard 8-pin networking connector used in


Ethernet cables such as CAT5 and CAT6. It is commonly used to connect devices like
computers, routers, switches, and modems in a local area network (LAN). The connector is
made of plastic with metal pins that establish electrical contact with the wires inside the cable.
It follows wiring standards such as T568A and T568B for proper data transmission. RJ-45
connectors are attached to cables using a crimping tool.

2. CAT-6 Cable: CAT-6 (Category 6) cable is a high-speed Ethernet cable used for networking
and internet connections. It consists of four twisted pairs of copper wires, which help reduce
interference and improve signal quality. CAT-6 supports data transfer speeds up to 1 Gbps over
standard distances and can handle higher bandwidth compared to older cables like CAT-5. It is
commonly used to connect computers, routers, switches, and other networking devices in a
LAN. The cable is terminated using RJ-45 connectors and installed using crimping tools. Due
to its reliability, speed, and performance, CAT-6 is widely used in modern networking systems.

2304221520025 3
Computer Networks Lab
BCS 653
3. Crimping Tool: A crimping tool is a handheld device used in networking to attach RJ-45
connectors to Ethernet cables such as CAT-5 and CAT-6. It is a multipurpose tool that can cut,
strip, and crimp cables efficiently. The tool ensures that the metal pins inside the connector
properly connect with the wires, allowing smooth data transmission. It is widely used by
technicians during network installation and maintenance. Proper use of the crimping tool
ensures a secure and reliable connection. It is easy to handle, durable, and essential for creating
custom-length LAN cables in homes, offices, and networking environments.

4. LAN Tester: A LAN tester is a device used to check the continuity and performance of
Ethernet cables such as CAT-5 and CAT-6. It helps identify wiring faults like open circuits,
short circuits, or incorrect pin connections. The tester usually consists of a main unit and a
remote unit, connected to both ends of the cable. When switched on, LED indicators glow in
sequence to show whether each wire is properly connected. It is an essential tool for network
installation and troubleshooting. LAN testers ensure reliable data transmission by verifying
correct cable wiring and are widely used by technicians in networking environments.

2304221520025 4
Computer Networks Lab
BCS 653

PRACTICAL – 3
Date: 20-02-2026

Objective: To design and simulate basic network topologies using CISCO Packet Tracer.

Step 1: Open Cisco Packet Tracer


1. Launch Cisco Packet Tracer.
2. Select File → New to create a new workspace.

Step 2: Add Network Devices


1. From bottom left device panel, select End Devices.
2. Drag 5 PCs into the workspace.
3. Now select Network Devices → Switches.
4. Drag one Switch (2960) into the center of the workspace.

Fig.1: All devices placed on the workspace

Step 3: Connect the Devices


1. Click on Connections.
2. Select Copper Straight-Through Cable.
3. Connect:
• PC0 → Switch (FastEthernet0/1)
• PC1 → Switch (FastEthernet0/2)
• PC2 → Switch (FastEthernet0/3)
• PC3 → Switch (FastEthernet0/4)
• PC4 → Switch (FastEthernet0/5)
Each PC should be connected to different Fast Ethernet ports of the switch. Now network
forms a Star Topology

2304221520025 5
Computer Networks Lab
BCS 653

Fig.2: Connection of devices in star topology

Step 4: Configure IP Addresses


1. Click on each PC and configure IP
addresses. For e.g., PC0 → Desktop → IP
Configuration

Device IP Address Subnet Mask


PC0 [Link] [Link]
PC1 [Link] [Link]
PC2 [Link] [Link]
PC3 [Link] [Link]
PC4 [Link] [Link]

Fig.3: IP address configuration of PCs

Step 5: Verify Connectivity


1. Click on PC0
2. Open Desktop → Command Prompt
3. Type: ping [Link]
If replies are received, the network is successfully configured.
Similarly, repeat for other PCs.

2304221520025 6
Computer Networks Lab
BCS 653

Fig.4: Network connectivity test using ping command

2304221520025 7
Computer Networks Lab
BCS 653

PROGRAM – 4
Date: 20-03-2025

Objective: To design and simulate a network using CISCO Packet Tracer where two
different network are connected.

Step 1: Open Cisco Packet Tracer


1. Launch Cisco Packet Tracer.
2. Select File → New to create a new workspace

Step 2: Add Network Devices


1. From bottom left device panel, select End Devices.
2. Drag 4 PCs into the workspace.
3. Now select Network Devices → Switches.
4. Drag two Switch (2960) into the center of the workspace
5. Now select Network Devices → Router.
6. Drag one Router (1841) into the center of the workspace

Fig.1: All devices placed on the workspace

Step 3: Connect the Devices


1. Click on Connections.
2. Select Copper Straight-Through Cable.
3. Connect:
• PC0 → Switch (FastEthernet0/1)
• PC1 → Switch (FastEthernet0/2)
• PC2 → Switch (FastEthernet1/1)
• PC3 → Switch (FastEthernet1/2)
• Switch0→Router (FastEthernet0/0)
• Switch1→Router (FastEthernet0/1)

2304221520025 8
Computer Networks Lab
BCS 653

Fig.2: Connection of devices

Step 4: Configure IP Addresses


1. Click on each PC and configure IP
addresses. For e.g., PC0 → Desktop → IP
Configuration

Device IP Address Subnet Mask Default Gateway


PC0 [Link] [Link] [Link]
PC1 [Link] [Link] [Link]
PC2 [Link] [Link] [Link]
PC3 [Link] [Link] [Link]

Fig.3: IP address configuration of PCs

2. Click on the Router and Config


For e.g., Router→ config→ FastEthernet0/0

Switch IP Address Subnet Mask


FastEthernet0/0 192.168.11 [Link]
FastEthernet0/0 [Link] [Link]

2304221520025 9
Computer Networks Lab
BCS 653

Fig.4: IP address configuration of Router

Step 5: Verify Connectivity


1. Click on PC0
2. Open Desktop → Command Prompt
3. Type: ping [Link]
If replies are received, the network is successfully configured.

Fig.5: Network connectivity test using ping command

2304221520025 10
Computer Networks Lab
BCS 653

PROGRAM – 5
Date: 03-04-2026

Objective: To implement Stop-and-Wait ARQ protocol.


[Link]
import [Link].*;
import [Link].*;
public class Sender {
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet, ack, str, msg;
int n, i = 0, sequence = 0;
public void run() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("Waiting for Connection....");
sender = new Socket("localhost", 2005);
out = new ObjectOutputStream([Link]());
[Link]();
in = new ObjectInputStream([Link]());
str = (String) [Link]();
[Link]("Receiver > " + str);
[Link]("Enter the data to send:");
packet = [Link]();
n = [Link]();
do {
if (i < n) {
msg = sequence + [Link](i, i + 1);
} else {
msg = "end";
[Link](msg);
[Link]();
break;
}
[Link](msg);
[Link]();
[Link]("Data Sent > " + msg);
ack = (String) [Link]();
if ([Link]([Link]((sequence + 1) % 2))) {
i++;
sequence = (sequence + 1) % 2;
[Link]("ACK received\n");
} else {
[Link]("Timeout... Resending\n");
}

} while (i <= n);


[Link]("All data sent.");
} catch (Exception e) {
2304221520025 11
Computer Networks Lab
BCS 653
[Link](e);
}
}
public static void main(String args[]) {
new Sender().run();
}
}

[Link]
import [Link].*;
import [Link].*;
public class Receiver {
ServerSocket receiver;
Socket connection;
ObjectOutputStream out;
ObjectInputStream in;
String packet, data = "";
int sequence = 0;
public void run() {
try {
receiver = new ServerSocket(2005);
[Link]("Waiting for connection...");
connection = [Link]();
out = new ObjectOutputStream([Link]());
[Link]();
in = new ObjectInputStream([Link]());
[Link]("Connected");
[Link]();
while (true) {
packet = (String) [Link]();
if ([Link]("end"))
break;
int seq = [Link]([Link](0, 1));
if (seq == sequence) {
data += [Link](1);
[Link]("Received: " + packet);
sequence = (sequence + 1) % 2;
} else {
[Link]("Duplicate packet: " + packet);
}
[Link]([Link](sequence));
[Link]();
}
[Link]("Data Received = " + data);
} catch (Exception e) {
[Link](e);
}
}
public static void main(String args[]) {
new Receiver().run();

2304221520025 12
Computer Networks Lab
BCS 653
}
}

OUTPUT

Figure 1: [Link]

Figure 2: [Link]

Figure 3: Sender sends message and receives acknowledgement

Figure 4: Receiver receives data

2304221520025 13
Computer Networks Lab
BCS 653

PROGRAM – 6
Date: 10-04-2026
Objective: Write a code simulating ARP/RARP protocols.
[Link]
import [Link].*;
import [Link].*;
public class Client {
public static void main(String args[]) {
try {
BufferedReader in = new BufferedReader(
new InputStreamReader([Link]));
Socket clsct = new Socket("[Link]", 5604);
BufferedReader din = new BufferedReader(
new InputStreamReader([Link]()));
DataOutputStream dout = new DataOutputStream(
[Link]());
[Link]("Enter the logical address (IP):");
String str1 = [Link]();
[Link](str1 + "\n");
String str = [Link]();
[Link]("The physical address is: " + str);
[Link]();
} catch (Exception e) {
[Link](e);
}
}
}

[Link]
import [Link].*;
import [Link].*;
public class Server {
public static void main(String args[]) {
try {
ServerSocket server = new ServerSocket(5604);
[Link]("Server started...");
[Link]("Waiting for client...");
Socket socket = [Link]();
[Link]("Client connected.");
BufferedReader br = new BufferedReader(
new InputStreamReader([Link]()));
DataOutputStream dout = new DataOutputStream([Link]());
String ip[] = { "[Link]", "[Link]" };
String mac[] = { "6A:08:AA:C2", "8A:BC:E3:FA" };
while (true) {
String str = [Link]();
if (str == null) {
[Link]("Client disconnected.");

2304221520025 14
Computer Networks Lab
BCS 653
break;
}
[Link]("Received IP: " + str);
boolean found = false;
for (int i = 0; i < [Link]; i++) {
if ([Link](ip[i])) {
[Link](mac[i] + "\n");
found = true;
break;
}
}
if (!found) {
[Link]("IP not found\n");
}
}
[Link]();
[Link]();
} catch (Exception e) {
[Link]("Error: " + e);
}
}
}

OUTPUT

Figure 1: [Link]

Figure 2: Client requests a physical address for a logical address

Figure 3: Server Connected to the Client and disconnected after replying to the request

2304221520025 15
Computer Networks Lab
BCS 653

PROGRAM – 07
Date: 17-04-2026

Objective: Write a code simulating PING and TRACEROUTE commands.

[Link]
import [Link].*;
import [Link].*;
class PingServer {
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter IP Address: ");
String ip = [Link]();
String os = [Link]("[Link]").toLowerCase();
Process p;
if ([Link]("win")) {
p = [Link]().exec("ping " + ip);
} else {
p = [Link]().exec("ping -c 4 " + ip);
}
BufferedReader input = new BufferedReader(
new InputStreamReader([Link]()));
String line;
while ((line = [Link]()) != null) {
[Link](line);
}
} catch (Exception e) {
[Link](e);
}
}

OUTPUT

2304221520025 16
Computer Networks Lab
BCS 653
[Link]
import [Link].*;
public class TracerouteCmd {
public static void runCommand(String command) {
try {
Process p = [Link]().exec(command);
BufferedReader input = new BufferedReader(
new InputStreamReader([Link]()));
String line;
while ((line = [Link]()) != null) {
[Link](line); }
} catch (Exception e) {
[Link](e);
}
}
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(
new InputStreamReader([Link]));
[Link]("Enter host: ");
String ip = [Link]();
String os = [Link]("[Link]").toLowerCase();
if ([Link]("win")) {
runCommand("tracert " + ip);
} else {
runCommand("traceroute " + ip); }
} catch (Exception e) {
[Link](e);
}
}
}
OUTPUT

2304221520025 17
Computer Networks Lab
BCS 653

PROGRAM – 08
Date: 24-04-2026

Objective: Study of Socket programming and Client-Server model.


[Link]
package Networking;
import [Link].*;
import [Link].*;
public class MyClient {
public static void main(String[] args) {
[Link]("Client started...");
try (
Socket socket = new Socket("localhost", 6666);
DataOutputStream out = new DataOutputStream([Link]());
DataInputStream in = new DataInputStream([Link]());) {
// Send message to server
[Link]("Hello Server");
[Link]();
// Receive reply from server
String response = [Link]();
[Link]("Server says: " + response);
} catch (IOException e) {
[Link]("Client error: " + [Link]());
}
}
}
[Link]
package Networking;
import [Link].*;
import [Link].*;
public class server {
public static void main(String[] args) {
[Link]("Server started...");
try (ServerSocket serverSocket = new ServerSocket(6666)) {
Socket socket = [Link](); // wait for one client
[Link]("Client connected!");
try (
DataInputStream in = new DataInputStream([Link]());
DataOutputStream out = new DataOutputStream([Link]());) {
// Receive message from client
String msg = [Link]();
[Link]("Client says: " + msg);
// Send response back
[Link]("Hello Client, message received!");
[Link]();}
[Link]();
} catch (IOException e) {
[Link]("Server error: " + [Link]());
}

2304221520025 18
Computer Networks Lab
BCS 653
}
}
OUTPUT

Figure 1: [Link]

Figure 2: client connect to server and send message

Figure 3: server receive message and send message to client

2304221520025 19
Computer Networks Lab
BCS 653

PROGRAM – 09
Date: 24-04-2026

Objective: To implement Checksum error detection technique in the Data Link Layer..
import [Link].*;
public class ChecksumFixed {
static int add(int a, int b, int size) {
int sum = a + b;
// Wrap around carry
int max = (1 << size) - 1;
if (sum > max) {
sum = (sum & max) + 1;
}
return sum;
}
static int complement(int num, int size) {
int max = (1 << size) - 1;
return (~num) & max;
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of blocks: ");
int n = [Link]();
[Link]("Enter block size: ");
int size = [Link]();
int[] data = new int[n];
[Link]("Enter binary data blocks:");
for (int i = 0; i < n; i++) {
data[i] = [Link]([Link](), 2);
}
int sum = data[0];
// Sender side
for (int i = 1; i < n; i++) {
sum = add(sum, data[i], size);
}
int checksum = complement(sum, size);
[Link]("Checksum: " +
[Link]("%" + size + "s",
[Link](checksum)).replace(' ', '0'));
// Receiver side
[Link]("Enter received data blocks:");
int receiverSum = 0;
for (int i = 0; i < n; i++) {
int val = [Link]([Link](), 2);
receiverSum = add(receiverSum, val, size);
}
receiverSum = add(receiverSum, checksum, size);
if (receiverSum == (1 << size) - 1) {
[Link]("No Error Detected");

2304221520025 20
Computer Networks Lab
BCS 653
} else {
[Link]("Error Detected");
}
[Link]();
}
}

OUTPUT

2304221520025 21
Computer Networks Lab
BCS 653

PROGRAM – 10
Date: 27-04-2026

Objective: To simulate congestion control using the Leaky Bucket Algorithm.


import [Link].*;
public class LeakyBucket {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int bucketSize, outputRate, n;
[Link]("Enter bucket size: ");
bucketSize = [Link]();
[Link]("Enter output rate: ");
outputRate = [Link]();
[Link]("Enter number of time intervals: ");
n = [Link]();
int[] packetSize = new int[n];
[Link]("Enter incoming packet sizes:");
for (int i = 0; i < n; i++) {
packetSize[i] = [Link]();
}
int currentBucket = 0;
[Link]("\nTime\tIncoming\tBucket\tOutput\tRemaining");
for (int i = 0; i < n; i++) {
int incoming = packetSize[i];
// Add incoming packets
if (currentBucket + incoming <= bucketSize) {
currentBucket += incoming;
} else {
int accepted = bucketSize - currentBucket;
int dropped = incoming - accepted;
currentBucket = bucketSize;
[Link](i + "\t" + incoming + "\t\tFULL\t0\tDropped: " + dropped);
continue;
}
// Output packets
int output = [Link](currentBucket, outputRate);
currentBucket -= output;
[Link](i + "\t" + incoming + "\t\t" +
(currentBucket + output) + "\t" +
output + "\t" + currentBucket);
}
[Link]();
}
}

2304221520025 22
Computer Networks Lab
BCS 653

OUTPUT

2304221520025 23
Computer Networks Lab
BCS 653

2304221520025 24

You might also like