Wa0015.
Wa0015.
231CS42B-NETWORKS LABORATORY
NAME :
REGISTER NO :
VM NO : VM - BRANCH :
AI&DS
YEAR : II
SEMESTER : IV
Vision
To promote centre of excellence through effectual Teaching and Learning, imparting the
contemporary knowledge centric education through innovative research in multidisciplinary fields.
Mission
To impart quality technical skills through practicing, knowledge updating in recent technology and
produce professionals with multidisciplinary and leadership skills.
To promote innovative thinking for design and development of software products of varying
complexity with intelligence to fulfil the global standards and demands.
To inculcate professional ethics among the graduates and to adapt the changing technologies
through lifelong learning.
An Autonomous Institution
Approved by AICTE, Affiliated to Anna University, Chennai.
ISO 9001:2015 Certified Institution, Accredited by NBA (BME, CSE, ECE, EEE, IT & MECH), Accredited by NAAC.
#42, Avadi-Vel Tech Road, Avadi, Chennai- 600062, Tamil Nadu, India.
CERTIFICATE
No………………….. College Roll No ........................... Certified that this is the bonafide record of work
Submitted for the University Practical Examination held on ............................ at VEL TECH MULTI
TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE, No.42, AVADI – VEL TECH
ROAD, AVADI, CHENNAI-600062.
Signature of Examiners
PEO1 Train the graduates with the potential of strong knowledge in the respective field and to create innovative
multidisciplinary solutions for challenges in the society
PEO2 Groom the engineers to understand, analyse different nature of data and use Machine Learning techniques
to develop software systems with varying complexity for data intensive applications
PEO3 To practice professionalism among the graduates and reflect good leadership skills with ethical standards
and continued professional development through lifelong learning.
PSO1 To impart theoretical knowledge in the respective field along with recent industrial tools and techniques to
solve societal problems
Apply the core competency obtained in the field of Machine Learning for analysis, design and development
PSO2 of computing systems for multi-disciplinary problems
PSO3 Acquire knowledge in the field of intelligence, deep learning and develop software solutions for security
and analytics of large volume of data.
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
WA1 PO1: Engineering Knowledge: Apply knowledge of mathematics, natural science, computing, engineering
fundamentals and an engineering specialization as specified in WK1 to WK4 respectively to develop to
the solution of complex engineering problems.
WA2 PO2: Problem Analysis: Identify, formulate, review research literature and analyze complex engineering
problems reaching substantiated conclusions with consideration for sustainable development. (WK1 to
WK4).
WA3 PO3: Design/Development of Solutions: Design creative solutions for complex engineering problems and
design/develop systems/components/processes to meet identified needs with consideration for the public
health and safety, whole-life cost, net zero carbon, culture, society and environment as required. (WK5).
WA4 PO4: Conduct Investigations of Complex Problems: Conduct investigations of complex engineering
problems using research-based knowledge including design of experiments, modelling, analysis &
interpretation of data to provide valid conclusions. (WK8).
WA5 PO5: Engineering Tool Usage: Create, select and apply appropriate techniques, resources and modern
engineering & IT tools, including prediction and modelling recognizing their limitations to solve complex
engineering problems. (WK2 and WK6).
PO6: The Engineer and The World: Analyze and evaluate societal and environmental aspects while solving
complex engineering problems for its impact on sustainability with reference to economy, health, safety,
WA6 legal framework, culture and environment. (WK1, WK5, and WK7).
WA7 PO7: Ethics: Apply ethical principles and commit to professional ethics, human values, diversity and
inclusion; adhere to national & international laws. (WK9).
WA8 PO8: Individual and Collaborative Team work: Function effectively as an individual, and as a member or
leader in diverse/multi-disciplinary teams.
WA9 PO9: Communication: Communicate effectively and inclusively within the engineering community and
society at large, such as being able to comprehend and write effective reports and design documentation,
make effective presentations considering cultural, language, and learning differences.
WA10
PO10: Project Management and Finance: Apply knowledge and understanding of engineering
management principles and economic decision-making and apply these to one’s own work, as a member
and leader in a team, and to manage projects and in multidisciplinary environments.
WA11 PO11: Life-Long Learning: Recognize the need for, and have the preparation and ability for i) independent
and life-long learning ii) adaptability to new and emerging technologies and iii) critical thinking in the
broadest context of technological change. (WK8)
COURSE OBJECTIVES
The student should be made to:
Attendance
Pre-Lab Practical Skills and Lab
and Post-Lab Quiz TOTAL
Preparation Experimentation Record(s)
Punctuality
10 15 25 15 10 75
EXP:NO:1
Aim:
To use commands like tcpdump, netstat, ifconfig, nslookup and trace route. Capture ping and
trace route PDUs using a network protocol analyzer and examine.
1. Tcpdump
Tcpdump is a command line utility that allows you to capture and analyze network traffic going
through your system.
Procedure
Check if tcpdump is installed on your system
$ which tcpdump
/usr/sbin/tcpdump
Iftcpdump is not installed,
$ sudo apt install tcpdump
To get Supervisor Privilege
$ su
(and password 123456)
$ sudo –i to change #
($ is changed to # and the commands can be executed in supervisor)
Capturing packets with tcpdump
Use the command tcpdump -D to see which interfaces are available for capture.
[root@localhost cse]# tcpdump -D
1.nflog (Linux netfilter log (NFLOG) interface)
2.nfqueue (Linux netfilter queue (NFQUEUE) interface)
3.usbmon1 (USB bus number 1)
4. enp2s0
5. usbmon2 (USB bus number 2)
6. any (Pseudo-device that captures on all interfaces)
7.lo [Loopback]
Capture all packets in any interface by running this command:
[root@localhost cse]# tcpdump -i any2
06:03:58.258143 ARP, Request who-has 172.16.51.87 tell 172.16.22.25, length 46
06:03:58.258225 ARP, Request who-has 172.16.51.88 tell 172.16.22.25, length 46
06:03:58.260828 ARP, Request who-has 172.16.51.122 tell 172.16.22.25, length 46
06:03:58.260903 ARP, Request who-has 172.16.51.123 tell 172.16.22.25, length 46
^C
5244 packets captured
1
59636 packets received by filter
54378 packets dropped by kernel
(Press ctrl+C to stop execution)
Filter packets based on the source or destination IP Address
[root@localhost ]#tcpdump -i any -c5 -nn src 172.16.20.138
6:10:30.712414 ARP, Request who-has 172.16.16.16 tell 172.16.20.138, length 28
06:10:31.483765 IP 172.16.20.138.47997 > 51.158.186.98.123: NTPv4, Client, length 48 5
packets captured
5 packets received by filter
0 packets dropped by kernel
[root@localhost ]#tcpdump -i any -c5 -nn dst 172.16.20.139
6:10:30.712414 ARP, Request who-has 172.16.16.16 tell 172.16.20.138, length 28
06:10:31.483765 IP 172.16.20.138.47997 > 51.158.186.98.123: NTPv4, Client, length 48 5
packets captured
5 packets received by filter
0 packets dropped by kernel
Ping command:
2. netstat netstat (network statistics) is a command line tool for monitoring network
connections both incoming and outgoing as well as viewing routing tables, interface
statistics etc.
2
3.
3.ifconfig:
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. It also
allows some control over active TCP/IP connections. Ipconfig replaced the older winipcfg utility.
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
4. nslookup
nslookup (stands for “Name Server Lookup”) is a useful command for getting information from
DNS server. It is a network administration tool for querying the Domain Name System (DNS) to
obtain undertakes from its source to its destination.
3
5. Traceroute:
4
INFERENCE:
RESULT:
EXP:NO:2
WRITE A HTTP WEB CLIENT PROGRAM TO DOWNLOAD A WEB PAGE USING
TCP SOCKET
5
AIM:
To Write a HTTP web client program to download a web page using TCP sockets.
ALGORITHM:
CLIENT SIDE:
1) Start the program.
2) Create a socket which binds the Ip address of server and the port address to acquire service.
3) After establishing connection send the url to server.
4) Open a file and store the received data into the file.
5) Close the socket.
6) End the program.
SERVER SIDE:
1) Start the program.
2) Create a server socket to activate the port address.
3) Create a socket for the server socket which accepts the connection.
4) After establishing connection receive url from client.
5) Download the content of the url received and send the data to client.
6) Close the socket.
7) End the program.
PROGRAM:
SERVER:
import java.net.*; import
java.io.*; import
java.awt.image.*; import
javax.imageio.*; import
javax.swing.*;
class Server {
6
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian); JFrame f = new
JFrame("Server"); ImageIcon icon = new
ImageIcon(bImage); JLabel
l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true); }}
CLIENT:
import java.net.*; import
java.awt.image.*; import
javax.imageio.*; import
java.io.*;
try {
// Establishing connection to the server soc =
new Socket("localhost", 4000);
System.out.println("Client is running. Connected to server.");
}
img = ImageIO.read(imageFile);
System.out.println("Reading image from disk.");
7
OutputStream out = soc.getOutputStream();
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
} finally {
// Ensure the socket is closed
try {
if (soc != null && !soc.isClosed()) {
soc.close();
System.out.println("Connection closed.");
}
} catch (IOException e) {
System.out.println("Error closing socket: " + e.getMessage()); }
}
}
OUTPUT:
SERVER:
CLIENT:
8
INFERENCE:
RESULT:
EXP:NO:3A APPLICATIONS USING TCP SOCKETS LIKE: A) ECHO CLIENT AND ECHO
SERVER
AIM:
ALGORITHM:
CLIENT SIDE
2. Create a socket which binds the Ip address of server and the port address to acquire
service.
9
5. Close the socket.
SERVER SIDE
3. Create a socket for the server socket which accepts the connection.
PROGRAM: ECHO
CLIENT:
import java.io.*;
import java.net.*;
public class eclient {
public static void main(String args[])
{
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os; try {
c=new Socket("localhost",8080);
} catch(IOException
e) {
System.out.println(e);
} try
{
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in); is1=new
DataInputStream(c.getInputStream()); do
{
10
System.out.println("client");
line=is.readLine(); os.println(line);
if(!line.equals("exit"))
System.out.println("server:"+is1.readLine());
}while(!line.equals("exit"));
} catch(IOException
e)
{
System.out.println("socket closed");
}}}
ECHO SERVER:
import java.io.*; import
java.net.*; import
java.lang.*; public
class eserver {
public static void main(String args[])throws IOException
{
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try {
s=new ServerSocket(8080);
}
catch(IOException e)
{
System.out.println(e);
} try { c=s.accept(); is=new
DataInputStream(c.getInputStream());
ps=new PrintStream(c.getOutputStream());
while(true) {
line=is.readLine();
System.out.println("msg received and sent back to client");
ps.println(line);
}}
catch(IOException e)
{
System.out.println(e);
}
}
}
OUTPUT:
ECHO SERVER:
11
ECHO CLIENT:
INFERENCE:
RESULT:
12
EXP:NO:3B APPLICATIONS USING TCP SOCKETS LIKE: CHAT
AIM:
ALGORITHM:
CLIENT
5. The client accept the connection and to send the data from client to server.
6. The client communicates the server to send the end of the message
SERVER
5. The server accept the connection and to send the data from server to client and
6. vice versa
7. The server communicate the client to send the end of the message.
13
PROGRAM: TCP
SERVER1:
import java.net.*;
import java.io.*;
System.out.println("Client connected!");
String line;
do {
line = clientInput.readLine(); // Read from client
if (line == null) break; // Handle client disconnection
} while (!line.equalsIgnoreCase("quit"));
System.out.println("Connection closed.");
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}}
TCP CLIENT1:
import java.net.*;
import java.io.*;
14
public static void main(String[] args) {
try (Socket socket = new Socket("192.168.23.196", 9999);
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
BufferedReader serverInput = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter serverOutput = new PrintWriter(socket.getOutputStream(), true)) {
do {
System.out.print("Client: ");
line = userInput.readLine(); // Read user input
if (serverResponse == null) {
System.out.println("Server disconnected.");
break;
}
System.out.println("Connection closed.");
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
OUTPUT:
15
TCPSERVER1:
TCPCLIENT1:
INFERENCE:
RESULT:
AIM:
16
To Perform File Transfer in Client & Server Using TCP/IP.
ALGORITHM:
CLIENT SIDE
1. Start.
5. After getting approval from the server ,the client either get file from the server or send
SERVER SIDE
1. Start.
3. Server reads the filename and sends the data stored in the file for the‘get’ request.
4. It reads the data from the input stream and writes it to a file in theserver for the ‘put’
instruction.
6. Stop.
PROGRAM:
SERVER:
17
import java.net.*;
import java.io.*; public
class FileServer
{ public static void main (String [] args ) throws IOException
{ ServerSocket servsock = new ServerSocket(13267);
while (true)
{
System.out.println("Waiting..."); Socket sock =
servsock.accept(); System.out.println("Accepte connection : " + sock);
File myFile = new File("source.pdf"); byte [] mybytearray = new byte
[(int)myFile.length()]; FileInputStream fis = new
FileInputStream(myFile); BufferedInputStream bis = new
BufferedInputStream(fis);
bis.read(mybytearray,0,mybytearray.length);
OutputStream os = sock.getOutputStream(); System.out.println("Sending...");
os.write(mybytearray,0,mybytearray.length);
os.flush(); sock.close();
}}}
CLIENT:
import java.net.*;
import java.io.*;
18
bytesRead = is.read(mybytearray, current, mybytearray.length - current);
if (bytesRead >= 0) current += bytesRead;
}
OUTPUT:
SERVER:
CLIENT:
19
INFERENCE:
RESULT:
AIM:
20
To write a program to Simulation of DNS using UDP sockets..
ALGORITHM:
5.If your frames reach the server it will send ACK signal to client otherwise it will send
PROGRAM:
SERVER:
{
private static int indexOf(String[] array, String str)
{ str =
str.trim(); for
(int i=0; i <
array.length;
i++)
{
if (array[i].equals(str)) return i;
} return -
1; }
21
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"};
System.out.println("Press Ctrl + C to Quit"); while (true){
}
}
}
CLIENT:
import java.io.*; import java.net.*; public
class udpdnsclient
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress; if (args.length == 0)
OUTPUT:
SERVER:
CLIENT:
23
INFERENCE:
OUTPUT:
EXP:NO:5
USE A TOOL LIKE WIRESHARK TO CAPTURE PACKETS AND EXAMINE THE
PACKETS
Aim :
To implement the code to capture packets and examine the packets using wireshark.
Procedure:
1. A network packet analyzer will try to capture network packets and tries to display that packet
data as detailed as possible.
24
Step 2:
Start the Wireshark application. When Wireshark is first run, a default, or blank window is
shown. To list the available network interfaces, select the Capture->Interfaces menu option.
Generate some network traffic with a Web Browser, such as Internet Explorer or Chrome. Your
Wireshark window should show the packets, and now look something like.
25
To stop the capture, select the Capture->Stop menu option, Ctrl+E, or the Stop toolbar button.
What you have created is a Packet Capture or ‘pcap’, which you can now view and analyse using
the Wireshark interface, or save to disk to analyse later.
1. Packet List Panel – this is a list of packets in the current capture. It colours the packets
based on the protocol type. When a packet is selected, the details are shown in the two panels
below.
2. Packet Details Panel – this shows the details of the selected packet. It shows the different
protocols making up the layers of data for this packet. Layers include Frame, Ethernet, IP,
TCP/UDP/ICMP, and application protocols such as HTTP.
3. Packet Bytes Panel – shows the packet bytes in Hex and ASCII encodings. To select
more detailed options when starting a capture, select the Capture->Options menu option, or
Ctrl+K, or the Capture Options button on the toolbar (the wrench).
26
Some of the more interesting options are:
Capture Options > Interface - Again the important thing is to select the correct Network
Interface to capture traffic through.
Capture Options > Capture File – useful to save a file of the packet capture in real time, in
case of a system crash.
Display Options > Update list of packets in real time – A display option, which should be
checked if you want to view the capture as it happens (typically switched off to capture straight
to a file, for later analysis).
Name Resolution > MAC name resolution – resolves the first 3 bytes of the MAC Address, the
Organisation Unique Identifier (OUI), which represents the Manufacturer of the Card. Name
Resolution > Network name resolution – does a DNS lookup for the IP Addresses captured, to
display the network name. Set to off by default, so covert scans do not generate this DNS traffic,
and tip off who’s packets you are sniffing.
Make sure the MAC name resolution is selected. Start the capture, and generate some Web
traffic again, then stop the capture.
27
Wireshark automatically generates a Display Filter, and applies it to the capture. The filter is
shown in the Filter Bar, below the button toolbar. Only packets captured with a Source Port of the
value selected should be displayed. The window should be similar to that shown in Figure 6. This
same process can be performed on most fields within Wireshark, and can be used to include or
exclude traffic.
Step 4:By using this we can capture the http ,So we can find the User name and login
28
29
INFERENCE:
RESULT:
EXP:NO:6
WRITE A CODE SIMULATING ARP/RARP PROTOCOL
Aim:
30
Algorithm:
Step 2 : In Client
Step 3: In Server
c.Server maintains the table in which IP and corresponding MAC addresses are stored.
e.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
{
Buff
ered
Rea
der
in=n
ew
Buff
ered
Rea
31
der(
new
Inpu
tStr
eam
Rea
der(
Syst
em.i
n));
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();
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();
32
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:
INFERENCE:
RESULT:
33
EXP:NO:7A STUDY OF NETWORK SIMULATOR (NS)
AIM:
INTRODUCTION :
Network Simulator (Version 2), widely known as NS2, is simply an eventdriven simulation tool
that has proved useful in studying the dynamic nature of communication networks. Simulation of
wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP)
can be done using NS2. In general, NS2 provides users with a way of specifying such network
protocols and simulating their corresponding behaviors. Due to its flexibility and modular nature,
NS2 has gained constant popularity in the networking research community since its birth in 1989.
Ever since, several revolutions and revisions have marked the growing maturity of the tool, thanks
to substantial contributions from the players in the field. Among these are the University of
California and Cornell University who developed the REAL network simulator, 1 the foundation
which NS is based on. Since 1995 the Defense Advanced Research Projects Agency (DARPA)
supported development of NS through the Virtual InterNetwork Testbed (VINT) project currently
the National Science Foundation (NSF) has joined the ride in development. Last but not the least,
the group of Researchers and developers in the community are constantly working to keep NS2
strong and versatile.
BASIC ARCHITECTURE
Figure shows the basic architecture of NS2. NS2 provides users with executable command ns
which take on input argument, the name of a Tcl simulation scripting file. Users are feeding the
34
name of a Tcl simulation script (which sets up a simulation) as an input argument of an NS2
executable command ns.
In most cases, a simulation trace file is created, and is used to plot graph and/or to create animation.
NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl).
While the C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the OTcl
sets up simulation by assembling and configuring the objects as well as scheduling discrete events
(i.e., a frontend).
The C++ and the OTcl are linked together using TclCL. Mapped to a C++ object, variables in the
OTcl domains are sometimes referred to as handles. Conceptually, a handle (e.g., n as a Node
handle) is just a string (e.g., _o10) in the OTcl domain, and does not contain any functionality.
Instead, the functionality (e.g., receiving a packet) is defined in the mapped C++ object (e.g., of
class Connector). In the OTcl domain, a handle acts as a frontend which interacts with users and
other OTcl objects. It may define its own procedures and variables to facilitate the interaction. Note
that the member procedures and variables in the OTcl domain are called instance procedures
(instprocs) and instance variables (instvars), respectively. Before proceeding further, the readers
are encouraged to learn C++ and OTcl languages. NS2 provides a large number of built-in C++
objects.
It is advisable to use these C++ objects to set up a simulation using a Tcl simulation script.
However, advance users may find these objects insufficient. They need to develop their own C++
objects, and use a OTcl configuration interface to put together these objects. After simulation, NS2
outputs either text-based or animation-based simulation results. To interpret these results
graphically and interactively, tools such as NAM (Network AniMator) and XGraph are used. To
analyze a particular behavior of the network, users can extract a relevant subset of text-based data
and transform it to a more conceivable presentation.
CONCEPT OVERVIEW :
ns uses two languages because simulator has two different kinds of things it needs to do. On one
hand, detailed simulations of protocols require a systems programming language which can
efficiently manipulate bytes, packet headers and implement algorithms that run over large data
sets. For these tasks run-time speed is important and turn-around time (run simulation, find bug,
fix bug, recompile, re-run) is less important. On the other hand, a large part of network research
involves slightly varying parameters or configurations, or quickly exploring number of scenarios.
35
In these cases, iteration time (change the model and re-run) is more important. Since
configuration runs once (at the beginning of the simulation), run-time of this part of the task is
less important. ns meets both of these needs with two languages, C++ and OTcl.
node]
Link failures
36
$ns rtmodel-at <time> up|down $n0 $n1
Application/Traffic/CBR]
Post-Processing Procedures
proc finish {}
global ns nf $ns
flush-trace
close $nf
exit 0
Schedule Events
Call ‘finish’
$ns run
37
RESULT:
Aim:
Algorithm
38
Step 2: Create two nodes n0 and n1.
a. Queuetype : Droptail
d. Queue size: 10
39
$ns trace-all $tr
# Create links
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail
40
set null [new Agent/Null] $ns
attach-agent $n3 $null
# Start applications
$ns at 0.0 "$ftp start"
$ns at 0.0 "$cbr start"
# End simulation
$ns at 5.0 "finish"
# Run simulation
$ns run
OUTPUT:
41
INFERENCE:
RESULT:
42
Aim :
2. The duplex links between n0 and n2, and n1 and n2 have 2 Mbps of bandwidth and 10 ms of
delay.
3. The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of delay.
4. Each node uses a DropTail queue, of which the maximum size is 10.
5. A "tcp" agent is attached to n0, and a connection is established to a tcp "sink" agent attached
to n3.
6. As default, the maximum size of a packet that a "tcp" agent can generate is 1KByte. 7. A tcp
"sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the
received packets.
10. A "ftp" and a "cbr" traffic generator are attached to "tcp" and "udp" agents respectively,
and the "cbr" is configured to generate 1 KByte packets at the rate of 1 Mbps.
11. The "cbr" is set to start at 0.1 sec and stop at 4.5 sec, and "ftp" is set to start at 1.0 sec
Program
43
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red #Open
the NAM trace file set nf
[open out.nam w]
$ns namtrace-all $nf
44
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection set
ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP #Setup
a UDP connection set udp
[new Agent/UDP] $ns
attach-agent $n1 $udp set
null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
45
46
INFERENCE:
47
RESULT:
EXP:NO:9A
SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM
Aim:
ALGORITHM:
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam on
trace file.
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program. Program (Distance Vector Protocol) set ns [new
Simulator] set nr [open thro.tr w] $ns trace-all $nr set nf [open thro.nam w] $ns namtrace-all
close $nr
48
exit 0 } for { set i 0 } { $i < 12} {
49
$ns rtproto DV
$ns at 45 "finish"
$ns run
OUTPUT:
50
INFERENCE:
RESULT::
51
EXP:NO:9B SIMULATION OF LINK STATE ROUTING ALGORITHM
Aim:
Algorithm:
3. Open a nam trace file and define finish procedure then close the trace file, and execute
nam
on trace file.
9. Choose Link state routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program. Program (Link State Protocol) set ns [new
Simulator] set nr [open link.tr w] $ns trace-all $nr set nf [open link.nam w] $ns
$ns flush-trace
close $nf
close $nr
52
4931_Grace College of Engineering,Thoothukudi
Application/Traffic/CBR]
$ns rtproto LS
53
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns at 45 "finish"
$ns run
OUTPUT:
54
INFERENCE:
RESULT:
Aim :
55
To write a program in Java to implement the Simulation of Error Correction Code Algorithm
At sender side
2. Read the number of bits to be sent. Let n be the Number of bits in data to be sent from sender
side.
3. Read the number of bits in the divisor. Let k be the Number of bits in the divisor (key
4. The binary data is first increased by adding k-1 zeros in the end of the data
5. Use modulo-2 binary division to divide binary data by the divisor and store remainder of
division.
6. Append the remainder at the end of the data to form the encoded data and send the same
At receiver side
1. Perform modulo-2 division again and if remainder is 0, then there are no errors.
Modulo 2 division
In each step, a copy of the divisor (or data) is XORed with the k bits of the dividend.
The result of the XOR operation (remainder) is (n-1) bits, which is used for the next step
When there are no bits left to pull down, we have a result. The (n-1)-bit remainder
import java.util.Scanner;
56
System.out.println("Enter received Hamming code: ");
String received = scanner.next();
scanner.close();
}
57
return p1 * 1 + p2 * 2 + p4 * 4 + p8 * 8;
}
OUTPUT:
58
INFERENCE:
RESULT:
Aim :
To write a program in Java to Implementations of Stop and Wait Protocol and Sliding Window
Protocol
Algorithm :
59
4. The sender sends one frame, stops until it receives confirmation from the receiver and then
sends the next frame.
5.Stop the program
Program:
import java.util.Random;
class SAP {
public static void main(String[] args) {
int[] frames = {1, 2, 3, 4, 5}; // Example frames
Random rand = new Random();
Output :
60
INFERENCE:
RESULT:
61
Aim :
To write a program in Java to Write a code simulating Go Back N ARQ.
ALGORITHM:
PROGRAM:
import java.util.Random;
class SWP {
static int WINDOW_SIZE = 3;
if (ackReceived) {
System.out.println("Acknowledgment received for frames: " + printFrames(frames,
base, end));
base += WINDOW_SIZE;
} else {
System.out.println("ACK lost, resending from Frame " + frames[base]);
}
System.out.println("-------------------");
62
}
}
Output :
INFERENCE:
RESULT:
63
EXNO: Real Time Port Scanner using Python -
DATE: Streamlit
Aim:
To build a real-time port scanner with a web dashboard using Streamlit, that
scans any IP address to detect open ports
Algorithm:
1. Start the application using Streamlit.
2.Take user input for IP address/domain and port range.
3.Resolve domain name to an IP address (if applicable).
4.Initialize a progress bar to track scanning progress.
5.Display a summary of all open ports in a clean, interactive table.
6.Show success message upon completion of scan.
7.End the program.
Program:
app.py
import streamlit as st
import socket
from scanner import scan_ports
import pandas as pd
# Progress indicator
st.subheader("📊 Scanning Progress")
progress_bar = st.progress(0)
progress_bar.current = 0
progress_bar.total = len(ports)
scanner.py:
import asyncio
import socket
writer.close()
await writer.wait_closed()
if progress:
progress.progress(min(progress.current + 1, progress.total))
progress.current += 1
return {"Port": port, "Status": "Open", "Banner": banner}
except:
if progress:
progress.progress(min(progress.current + 1, progress.total))
progress.current += 1
return {"Port": port, "Status": "Closed", "Banner": "-"}
Result:
Thus, the python streamlit application for real time port scanner which scans
port has been successfully implemented.