Lab CS3591 COMPUTER NETWORKS LAB
Lab CS3591 COMPUTER NETWORKS LAB
Lab CS3591 COMPUTER NETWORKS LAB
DHARMAPURI
(REGULATION 2021)
Prepared By,
Mrs.R.S.Archana Vishveswari,
AP/CSE
AIM:
Learn to use commands like tcpdump, netstat, ifconfig, nslookup and tracert. Capture ping and
trace route PDUs using a network protocol analyzer and examine.
Commands:
1. Netstat:
Netstat provides information and statistics about protocols in use and current TCP/IP network
connections. The Windows help screen (analogous to a Linux or UNIX for netstat reads as
follows: displays protocol statistics and current TCP/IP network connections.
2. TCPDUMP:
Provide the protocol as an argument to display only traffic for a specific protocol, for example
TCP, UDP, ICMP, ARP,
# tcpdump protocol For example to display traffic only for the tcp traffic.
# tcpdump tcp Filtering based on source or destination port To filter based on a source or
destination Port.
3. Ipconfig:
In Windows, ipconfig is a console application designed to run from the Windows command
prompt. This utility allows you to get the IP address information of a Windows computer.
Using ipconfig
From the command prompt, type ipconfig to run the utility with default options. The output of the
default command contains the IP address, network mask, and gateway for all physical and virtual
network adapter.
#ipconfig
The nslookup command is a powerful tool for diagnosing DNS problems. You know you're experiencing a
DNS problem when you can access a resource by specifying its IP address but not its DNS name.
#nslookup
5.Trace route:
Traceroute uses Internet Control Message Protocol (ICMP) echo packets with variable time to live (TTL)
values. The response time of each hop is calculated. To guarantee accuracy, each hop is queried multiple
times (usually three times) to better measure the response of that particular hop.
Traceroute is a network diagnostic tool used to track the pathway taken by a packet on an IP network from
source to destination. Traceroute also records the time taken for each hop the packet makes during its route
The response time of each hop is calculated. To guarantee accuracy, each hop is queried multiple times
(usually three times) to better measure the response of that particular hop. Traceroute sends packets with
TTL values that gradually increase from packet to packet, starting with TTL value of one. Routers
decrement TTL values of packets by one when routing and discard packets whose TTL value has reached
zero, returning the ICMP error message ICMP Time Exceeded.For the first set of packets, the first router
receives the packet, decrements the TTL value and drops the packet because it then has TTL value zero.
The router sends an ICMP Time Exceeded message back to the source. The next set of packets are given a
TTL value of two, so the first router forwards the packets, but the second router drops them and replies
with ICMP Time Exceeded.
Proceeding in this way, traceroute uses the returned ICMP Time Exceeded messages to build a list of
routers that packets traverse, until the destination is reached and returns an ICMP Echo Reply message.
With the tracert command shown above, we're asking tracert to show us the path from the local computer
all the way to the network device with the hostname.
6.Ping:
The ping command sends an echo request to a host available on the network. Using this
command, you can check if your remote host is responding well or not. Tracking and isolating
hardware and software problems. Determining the status of the network and various foreign
hosts. The ping command is usually used as a simple way to verify that a computer can
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
communicate over the network with another computer or network device. The ping command
operates by sending Internet Control Message Protocol (ICMP) Echo Request messages to the
destination computer and waiting for a response.
Thus the various networks commands like tcpdump, netstat, ifconfig, nslookup and
tracert, ping are executed successfully.
AIM:
To write a HTTP web client program to download a web page using TCP sockets.
PROCEDURE:
TCP connection with the web server using a Socket. We then use the socket's input and output
streams to send an HTTP GET request and receive the server's response.
Replace "example.com" with the actual domain name or IP address of the web page you want to
download. You can also modify the port and path variables as needed.
Keep in mind that this is a basic example, and it assumes that the web server is listening on the
standard HTTP port (port 80).
In a real-world scenario, you might need to handle redirects, handle different response codes,
handle chunked encoding, and so on.
PROGRAM:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class WebPageDownloader
{
public static void main(String[] args)
{
String host = "example.com";
int port = 80;
String path = "/";
try (Socket socket = new Socket(host, port);
PrintWriter requestWriter = new PrintWriter(socket.getOutputStream());
BufferedReader responseReader = new BufferedReader(new
InputStreamReader(socket.getInputStream()
)))
{
OUT PUT:
AIM:
Write a program for Echo Client and Echo server using TCP sockets.
PROCEDURE:
b) Echo Client.java:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class EchoClient
{
public static void main(String[] args)
{
String serverAddress = "localhost";
int port = 12345;
try (Socket socket = new Socket(serverAddress, port);
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
Scanner scanner = new Scanner(System.in));
{
System.out.println("Connected to EchoServer at " + serverAddress + ":" + port);
System.out.println("Type a message and press Enter to send, or type 'exit' to quit.");
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
// Read input from the user and send it to the server String input;
do
{
input = scanner.nextLine();
writer.println(input);
String response = reader.readLine();
System.out.println("Server response: " + response);
}
while (!input.equalsIgnoreCase("exit"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Out Put:
AIM:
To write a program for the Chat Applications using TCP sockets.
PROCEDURE:
Compile both ChatServer.java and ChatClient.java using javac.
Start the server by running java ChatServer in one terminal or command prompt window.
Start multiple clients by running java ChatClient in separate terminal or command
prompt windows.
Each client can type messages, and they will be broadcasted to all connected
clients.
PROGRAMS:
A) ChatServer.java
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer
{
private static final int PORT = 12345;
private static Set<Socket> clientSockets = new HashSet<>();
private static final Object lock = new Object();
public static void main(String[] args)
{
try (ServerSocket serverSocket = new ServerSocket(PORT))
{
System.out.println("ChatServer is listening on port " + PORT);
while (true)
{
Socket clientSocket = serverSocket.accept();
System.out.println("Client connected: " + clientSocket.getInetAddress().
getHostAddress());
synchronized (lock)
{
clientSockets.add(clientSocket);
}
Thread clientThread = new Thread(() -> handleClient(clientSocket));
clientThread.start();
}
} catch (IOException e)
{
e.printStackTrace();
}
}
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
private static void handleClient(Socket clientSocket)
{
try (BufferedReader reader = new BufferedReader(new InputStreamReader
(clientSocket.getInputStream()));
PrintWriter writer = new PrintWriter(clientSocket.getOutputStream(), true))
{
String clientMessage;
while ((clientMessage = reader.readLine()) != null)
{
System.out.println("Received from client: " + clientMessage);
// Broadcast the message to all connected clients
synchronized (lock) {
for (Socket socket : clientSockets) {
PrintWriter clientWriter = new PrintWriter(socket.getOutputStream(), true);
clientWriter.println(clientMessage);
}
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
synchronized (lock)
{
clientSockets.remove(clientSocket);
}
System.out.println("Client disconnected: " + clientSocket.getInetAddress().
getHostAddress());
}
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
}
B) ChatClient.java
import java.io.*;
import java.net.*;
import java.util.Scanner;
InputStreamReader(socket.getInputStream()));
System.out.println("Type your messages and press Enter to send, or type 'exit' to quit.");
String serverMessage;
try
} catch (IOException e)
e.printStackTrace();
});
receiveThread.start();
// Read input from the user and send messages to the server
String input;
Do
input = scanner.nextLine();
writer.println(input);
while (!input.equalsIgnoreCase("exit"));
catch (IOException e)
e.printStackTrace();
OUT PUT:
AIM:
To write a program for Simulation of DNS using UDP sockets
PROCEDURE:
The DNS server listens on port 53, which is the standard DNS port. It receives DNS queries
from clients, processes them, and sends back the corresponding IP address. The process DNSQuery()
method is a placeholder where you can implement your own logic to map domain names to IP
addresses.
To test the DNS server, you can use a DNS client program or a tool like nslookup. Here's an
example using the nslookup command:
Compile and run the DNS server program using javac DNSServer.java and java DNSServer.
Open a new terminal or command prompt window.
Type nslookup example.com localhost to query the DNS server for the IP address of example.com.
Replace localhost with the IP address or hostname of the machine running the DNS server.
You should see the DNS server responding with the IP address for example.com.
Note that this is a basic example and does not cover all the complexities of a full-fledged DNS
server. It's intended to demonstrate the concept of simulating DNS using UDP sockets.
PROGRAM:
import java.net.*;
while (true)
socket.receive(requestPacket);
socket.send(responsePacket);
catch (Exception e)
e.printStackTrace();
switch (query)
case "example.com":
return "192.0.2.1";
case "google.com":
return "8.8.8.8";
default:
OUT PUT:
AIM:
Use a tool wire shark to capture a packets and examine the packets.
PROCEDURE:
Wireshark is a powerful network protocol analyzer that allows you to capture and analyze
network packets. Here's how you can use Wireshark to capture packets and examine them:
1. Start Wireshark on your machine.
2. Select the network interface that you want to capture packets from. For example, if you're using
Wi-Fi, select the Wi-Fi interface. If you're using Ethernet, select the Ethernet interface.
3. Click on the "Start" button to begin capturing packets.
4. Run your DNS server program (as described in the previous response) or any other network
program that generates network traffic.
5. Perform the actions or execute the program that generates the network traffic you want to
capture and examine. For example, if you're using the DNS server program, you can use the
nslookup command or any other DNS client program to perform DNS queries.
6. Once you're done generating the network traffic, go back to Wireshark and click on the "Stop"
button to stop capturing packets.
AIM:
To write a program to simulate ARP/RARP protocol.
PROCEDURE:
In this simulation, we have a simple ARPTable class that stores IP-MAC address mappings. The
ARPProtocolSimulator class demonstrates the usage of this table to simulate ARP and RARP lookups.
To run the simulation, simply compile and execute the ARPProtocolSimulator.java file. It will
perform an ARP lookup by querying the ARP table for a given IP address and display the corresponding
MAC address if found. It will also perform a RARP lookup by searching the ARP table for a given
MAC address and display the corresponding IP address if found.
Note that this is a basic simulation for educational purposes and doesn't involve actual network
communication. In real-world scenarios, ARP and RARP involve communication between devices on a
network to resolve IP and MAC addresses.
RESULT:
Thus the above program to simulate ARP/RARP protocol has been executed successfully.
AIM:
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS.
PROCEDURE:
Network Simulator (NS) is a discrete event network simulation tool used for simulating and
evaluating the performance of computer networks. It allows researchers and network engineers to
simulate various network scenarios, protocols, and algorithms to understand their behaviour and
performance under different conditions.
NS is widely used for academic and research purposes to explore network concepts, test new
protocols, study network behaviour, and evaluate network performance. It provides a flexible and
extensible environment for designing network topologies, defining network parameters, and running
simulations.
Some key features of NS include:
Network Topology: NS allows users to create complex network topologies with nodes, links, and
routers. It supports various network types, including wired and wireless networks.
Protocol Simulation: NS provides a library of network protocols that can be simulated, such as
TCP/IP, UDP, routing protocols (e.g., OSPF, BGP), and congestion control algorithms.
Traffic Generation: NS allows users to generate traffic patterns and flows to simulate realistic
network traffic scenarios. This enables the evaluation of network performance and congestion
control algorithms under different traffic conditions.
Event-driven Simulation: NS operates on an event-driven model, where events (such as packet
arrivals, link failures, or timer expirations) are scheduled and processed based on simulation
time. This allows for fine-grained control and synchronization of network events.
Performance Metrics: NS provides built-in tools for collecting and analysing performance
metrics during simulations. These metrics can include throughput, latency, packet loss,
congestion indicators, and more.
Now, let's discuss simulating Congestion Control Algorithms using NS. Congestion control
algorithms aim to manage network congestion and optimize network performance by regulating the rate
at which data is transmitted. NS enables researchers to simulate and evaluate different congestion
control algorithms and compare their performance in various network scenarios.
To simulate congestion control algorithms using NS, you would typically follow these steps:
Design the network topology:
Define the network topology you want to simulate, including nodes, links, and their properties.
Implement the congestion control algorithm:
Write the code or configure the congestion control algorithm within NS. NS provides a
programming interface to implement custom congestion control algorithms or use existing ones
available in the library.
Define traffic patterns:
Specify the traffic patterns and flows that will be generated in the network. This can include
different types of traffic, such as bulk data transfers, real-time traffic, or background traffic.
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
Run the simulation: Start the simulation and let NS simulate the network behaviour over time.
NS will handle events, process packets, and simulate the congestion control algorithm's actions based on
the defined network conditions and traffic patterns.
Collect and analyse results:
Monitor and collect performance metrics during the simulation, such as throughput, delay,
packet loss, and congestion indicators. Analyse the results to evaluate the effectiveness and efficiency of
the congestion control algorithm under different scenarios.
Iterate and refine:
Based on the simulation results, refine the congestion control algorithm or experiment with different
parameter settings to optimize network performance.
NS provides extensive documentation, tutorials, and examples to help users get started with
simulating congestion control algorithms and exploring network behaviour. You can refer to the official
NS documentation and resources for detailed guidance on using NS for congestion control simulations.
Keep in mind that simulating congestion control algorithms in NS provides a controlled
environment for evaluation and comparison. Real-world network deployments may introduce additional
complexities and factors that can impact the algorithm's performance. Therefore, it's essential to validate
the simulation results with real-world experiments when possible.
RESULT:
AIM:
Study of TCP/UDP using simulation tool.
PROCEDURE:
To study the performance of TCP (Transmission Control Protocol) and UDP (User Datagram
Protocol) using simulation tools, you can use network simulators like Network Simulator (NS), ns-3, or
OMNeT++ that provide support for simulating these protocols. Here's an overview of the process:
Protocol Configuration:
Configure the simulation environment to use TCP and UDP protocols. Specify the parameters
and settings related to these protocols, such as TCP congestion control algorithms (e.g., Reno, Cubic) or
UDP packet sizes.
Traffic Generation:
Define the traffic patterns and flows that will be generated in the network. Decide on the types of
traffic, such as bulk transfers, video streaming, or real-time communications. Set the traffic
characteristics, such as arrival rates, sizes, and destinations, to mimic real-world scenarios.
Simulation Execution:
Simulation tools like NS, ns-3, or OMNeT++ provide extensive documentation, example
scenarios, and libraries that facilitate the simulation of TCP and UDP. You can consult their
documentation and resources to learn more about using these tools to study the performance of TCP and
UDP protocols in different network scenarios.
Keep in mind that while simulations provide valuable insights, they may not fully capture the
complexity of real-world networks. Therefore, it's important to complement the simulation results with
real-world experiments whenever possible to validate and verify the findings.
AIM:
To simulate the Distance Vector routing algorithm
PROCEDURE:
To simulate the Distance Vector routing algorithm, you can use network simulation tools like
Network Simulator (NS), ns-3, or OMNeT++. Here's a step-by-step guide on simulating the Distance
Vector algorithm:
Network Topology Design:
Design the network topology you want to simulate. Define the nodes and links in the network,
including their properties such as bandwidth, delay, and reliability. Consider the size and complexity of
the network to reflect the scenario you want to study.
Node Configuration:
Configure each node in the network to use the Distance Vector routing algorithm. Each node
should maintain its routing table and exchange routing updates with its neighboring nodes.
Traffic Generation:
Define the traffic patterns and flows to be used in the simulation. Generate traffic between nodes
to simulate realistic network conditions. Specify the type, volume, and source-destination pairs of the
traffic flows based on your study objectives.
Simulation tools like NS, ns-3, or OMNeT++ provide libraries, modules, and example scenarios
to facilitate the simulation of the Distance Vector algorithm. You can refer to their documentation and
resources for specific guidance on using these tools for Distance Vector simulations.
Remember that simulations provide insights into the behavior of routing algorithms but may not
fully capture the complexity of real-world networks. Therefore, it's important to complement simulation
results with real-world experiments whenever possible to validate and verify the findings.
RESULT:
AIM:
Simulation of Link State Routing algorithm.
PROCEDURE:
To simulate the Link State routing algorithm, you can use network simulation tools like Network
Simulator (NS), ns-3, or OMNeT++. Here's a step-by-step guide on simulating the Link State algorithm:
Network Topology Design:
Design the network topology you want to simulate. Define the nodes and links in the network,
including their properties such as bandwidth, delay, and reliability. Consider the size and complexity of
the network to reflect the scenario you want to study.
Node Configuration:
Configure each node in the network to use the Link State routing algorithm. Each node should
have a Link State Database (LSDB) that stores information about the network's topology.
Packet Forwarding:
During the simulation, when a packet needs to be forwarded, the source node consults its routing
table to determine the next hop and forwards the packet accordingly.
Simulation Execution:
Run the simulation using the selected simulation tool. The simulation will execute the Link State
algorithm, update the LSDBs, calculate shortest paths, and forward packets based on the routing tables.
Traffic Generation:
Define the traffic patterns and flows to be used in the simulation. Generate traffic between nodes
to simulate realistic network conditions. Specify the type, volume, and source-destination pairs of the
traffic flows based on your study objectives.
Performance Metrics Collection:
Monitor and collect performance metrics during the simulation to evaluate the Link State
algorithm's performance. Common metrics include routing convergence time, packet delivery ratio, end-
RESULT:
Thus the above simulation program has been executed successfully.
AIM:
Simulation of an error correction code (CRC).
PROCEDURE:
To simulate an error correction code like CRC (Cyclic Redundancy Check), you can use
programming languages like Python to create a simulation program. Here's a step-by-step guide on
simulating CRC:
Select CRC Parameters:
By implementing the CRC algorithm in a programming language, you can simulate the error
detection and correction process. You can modify the simulation program to test different CRC
parameters, error patterns, or even combine CRC with other error correction techniques.
Remember that this simulation represents a simplified version of real-world scenarios, and CRC
is just one type of error correction code. More complex error correction codes, such as Reed-Solomon
codes, may require additional considerations and calculations.
PREPARED BY, PROF, R.S.ARCHANA VISHVESWARI, M.TECH, 6128-VVIT
RESULT:
Thus the above simulation program has been executed successfully.