CN - Lab - Manual CSM
CN - Lab - Manual CSM
SEMISTER : III-II
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE ENGINEERING (AI&ML)
III-II CSE (AI&ML) PAGE NO:
CERTIFICATE
This is certify that is the bona fide record of the work done in_______________________________
Laboratory by Mr./Ms________________________________________________________________
Course during_______________________________________________________________________
EXTERNAL EXAMINAR
INDEX
Wireshark
i. Packet Capture Using Wire shark
13 ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters
Experiment-1
AIM: Study of Network devices in detail and connect the computers in Local Area Network.
Network Devices: Network devices, also known as networking hardware, are physical
devices that allow hardware on a computer network to communicate and interact with one
another. For example Repeater, Hub, Bridge, Switch, Routers, Gateway and NIC, etc.
1. Repeater – A repeater operates at the physical layer. Its job is to regenerate the signal over
the same network before the signal becomes too weak or corrupted to extend the length to
which the signal can be transmitted over the same network. An important point to be noted
about repeaters is that they not only amplify the signal but also regenerate it. When the
signal becomes weak, they copy it bit by bit and regenerate it at its star topology connectors
connecting following the original strength. It is a 2-port device.
2. Hub – A hub is a basically multi-port repeater. A hub connects multiple wires coming from
different branches, for example, the connector in star topology which connects different
stations. Hubs cannot filter data, so data packets are sent to all connected devices. In other
words, the collision domain of all hosts connected through Hub remains one. Also, they do
not have the intelligence to find out the best path for data packets which leads to
inefficiencies and wastage.
Types of Hub
Active Hub:- These are the hubs that have their power supply and can clean, boost, and
relay the signal along with the network. It serves both as a repeater as well as a wiring
center. These are used to extend the maximum distance between nodes.
Passive Hub:- These are the hubs that collect wiring from nodes and power supply from
the active hub. These hubs relay signals onto the network without cleaning and boosting
them and can’t be used to extend the distance between nodes.
Intelligent Hub:- It works like an active hub and includes remote management
capabilities. They also provide flexible data rates to network devices. It also enables an
administrator to monitor the traffic passing through the hub and to configure each port in
the hub.
3. Bridge – A bridge operates at the data link layer. A bridge is a repeater, with add on the
functionality of filtering content by reading the MAC addresses of the source and
destination. It is also used for interconnecting two LANs working on the same protocol. It
has a single input and single output port, thus making it a 2 port device.
Transparent Bridges:- These are the bridge in which the stations are completely unaware
of the bridge’s existence i.e. whether or not a bridge is added or deleted from the network,
reconfiguration of the stations is unnecessary. These bridges make use of two processes i.e.
bridge forwarding and bridge learning.
Source Routing Bridges:- In these bridges, routing operation is performed by the source
station and the frame specifies which route to follow. The host can discover the frame by
sending a special frame called the discovery frame, which spreads through the entire
network using all possible paths to the destination.
4. Switch – A switch is a multiport bridge with a buffer and a design that can boost its
efficiency(a large number of ports imply less traffic) and performance. A switch is a data
link layer device. The switch can perform error checking before forwarding data, which
makes it very efficient as it does not forward packets that have errors and forward good
packets selectively to the correct port only. In other words, the switch divides the collision
domain of hosts, but the broadcast domain remains the same.
Types of Switches
Unmanaged switches: These switches have a simple plug-and-play design and do not
offer advanced configuration options. They are suitable for small networks or for use as
an expansion to a larger network.
Managed switches: These switches offer advanced configuration options such as VLANs,
QoS, and link aggregation. They are suitable for larger, more complex networks and allow
for centralized management.
Smart switches: These switches have features similar to managed switches but are
typically easier to set up and manage. They are suitable for small- to medium-sized
networks.
PoE switches: These switches have Power over Ethernet capabilities, which allows them
to supply power to network devices over the same cable that carries data.
Gigabit switches: These switches support Gigabit Ethernet speeds, which are faster than
traditional Ethernet speeds.
Rack-mounted switches: These switches are designed to be mounted in a server rack and
are suitable for use in data centers or other large networks.
Desktop switches: These switches are designed for use on a desktop or in a small office
environment and are typically smaller in size than rack-mounted switches.
Modular switches: These switches have modular design, which allows for easy expansion
or customization. They are suitable for large networks and data centers.
5. Routers – A router is a device like a switch that routes data packets based on their IP
addresses. The router is mainly a Network Layer device. Routers normally connect LANs
and WANs and have a dynamically updating routing table based on which they make
decisions on routing the data packets. The router divides the broadcast domains of hosts
connected through it.
6. Gateway – A gateway, as the name suggests, is a passage to connect two networks that may
work upon different networking models. They work as messenger agents that take data from
one system, interpret it, and transfer it to another system. Gateways are also called protocol
converters and can operate at any network layer. Gateways are generally more complex than
switches or routers. A gateway is also called a protocol converter.
7. Brouter – It is also known as the bridging router is a device that combines features of both
bridge and router. It can work either at the data link layer or a network layer. Working as a
router, it is capable of routing packets across networks and working as the bridge, it is
capable of filtering local area network traffic.
8. NIC – NIC or network interface card is a network adapter that is used to connect the
computer to the network. It is installed in the computer to establish a LAN. It has a unique
id that is written on the chip, and it has a connector to connect the cable to it. The cable acts
as an interface between the computer and the router or modem. NIC card is a layer 2 device
which means that it works on both the physical and data link layers of the network model.
Experiment-2
AIM: Write a Program to implement the data link layer farming methods such as
i) Character stuffing ii) bit stuffing.
i) Character Stuffing:
SOURCE CODE:
#include<stdio.h>
#include<string.h>
int main()
{
char a[30], b[30], c[30];
int len, i, j = 0, k = 0;
printf("Enter the string: ");
gets(a);
len = strlen(a);
printf("The frames after stuffing:\n");
printf("dlestx\t");
for (i = 0; i < len; i++)
{
if ((a[i] == 'd' && a[i + 1] == 'l' && a[i + 2] == 'e') ||
(a[i] == 's' && a[i + 1] == 't' && a[i + 2] == 'x') ||
(a[i] == 'e' && a[i + 1] == 't' && a[i + 2] == 'x'))
{
b[j++] = 'D';
b[j++] = 'L';
b[j++] = 'E';
b[j++] = a[i];
b[j++] = a[i + 1];
b[j++] = a[i + 2];
i += 2;
}
OUTPUT:
Enter the string: IAMLOVINGYOU
The frames after stuffing:
dlestx IAMLOVINGYOU dleetx
The character destuffing is: IAMLOVINGYOU
OUTPUT:
Enter frame length:5
Enter input frame (0's & 1's only):
1
1
1
1
1
After stuffing the frame is:111110
Experiment-3
AIM: Write a Program to implement data link layer farming method checksum.
SOURCE CODE:
#include <stdio.h>
#include <string.h>
int main()
{
char a[20], b[20];
char sum[20], complement[20];
int i, length;
printf("Enter first binary string\n");
scanf("%s", a);
printf("Enter second binary string\n");
scanf("%s", b);
if (strlen(a) == strlen(b))
{
length = strlen(a);
char carry = '0';
for (i = length - 1; i >= 0; i--)
{
if (a[i] == '0' && b[i] == '0' && carry == '0')
{
sum[i] = '0';
carry = '0';
}
else if (a[i] == '0' && b[i] == '0' && carry == '1')
{
sum[i] = '1';
carry = '0';
}
OUTPUT:
Enter first binary string
1011
Enter second binary string
1100
Sum=1000
Checksum=0111
Experiment-4
AIM: Write a program for Hamming Code generation for error detection and correction.
SOURCE CODE:
#include<stdio.h>
void main()
{
int data[10];
int dataatrec[10],c,c1,c2,c3,i;
printf("Enter 4 bits of data one by one\n");
scanf("%d",&data[0]);
scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];
printf("\nEncoded data is\n");
for(i=0;i<7;i++) {
printf("%d",data[i]);
}
printf("\n\nEnter received data bits one by one\n");
for(i=0;i<7;i++) {
scanf("%d",&dataatrec[i]);
}
c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;
if(c==0)
{
OUTPUT:
Enter 4 bits of data one by one
1
0
1
0
Encoded data is
1010010
Experiment-5
AIM: Write a Program to implement on a data set of characters the three CRC polynomials –
CRC 12, CRC 16 and CRC CCIP.
SOURCE CODE:
#include<stdio.h>
#include<string.h>
int main()
{
int i, j, keylen, msglen, msglen1;
char input[100], key[30], temp[30], quot[100], rem[30], key1[30], r[100];
printf("Enter Data: ");
gets(input);
printf("Enter Key: ");
gets(key);
keylen = strlen(key);
msglen = strlen(input);
strcpy(key1, key);
for (i = 0; i < keylen - 1; i++)
{
input[msglen + i] = '0';
}
printf("After adding 0's in the input is: ");
for (i = 0; i < msglen + keylen - 1; i++)
{
temp[i] = input[i];
printf("%c", input[i]);
}
for (i = 0; i < keylen; i++)
{
temp[i] = input[i];
OUTPUT:
Enter Data: 1101011011
Enter Key: 10011
After adding 0's in the input is: 11010110110000
Quotient is: 1100001010
Remainder is: 1110
Transmitted data is: 11010110111110
Enter the received data: 11010110111110
Success
Experiment-6
AIM: Write a Program to implement Sliding window protocol for Goback N.
SOURCE CODE:
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent == windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);
if(ack == windowsize)
break;
else
sent = ack;
}
return 0;
}
OUTPUT:
enter window size
5
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Experiment-7
AIM: Write a Program to implement Sliding window protocol for Selective repeat.
SOURCE CODE:
#include<stdio.h>
int main()
{
int windowsize,sent=0,nack[10],neg,i;
printf("enter window size\n");
scanf("%d",&windowsize);
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",i);
}
printf("\nPlease enter the number of negative acknowledgements received.\n");
scanf("%d",&neg);
printf("\nPlease enter the negative acknowledgements received.\n");
for( i = 0; i < neg; i++)
{
scanf("%d",&nack[i]);
}
for( i = 0; i < neg; i++)
{
printf("Frame %d has been retransmitted.\n",nack[i]);
}
return 0;
}
OUTPUT:
enter window size
4
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Experiment-8
AIM: Write a Program to implement Stop and Wait Protocol.
SOURCE CODE:
#include<stdio.h>
int main() {
int i,framesize,frame[50];
printf("Enter number of frames to transmit:");
scanf("%d",&framesize);
printf("\nEnter the data frames to transmit:");
for(i=0;i<framesize;i++) {
scanf("%d",&frame[i]);
}
for(i=0;i<framesize;i++) {
printf("frame %d containing data %d has been transmitted",i,frame[i]);
printf("ack %d has been received",i);
}
printf("stop and wait protocol ends");
return 0;
}
OUTPUT:
Enter number of frames to transmit:2
Enter the data frames to transmit:
1
3
frame 0 containing data 1 has been transmitted
ack 0 has been received
frame 1 containing data 3 has been transmitted
ack 1 has been received
stop and wait protocol ends
Experiment-9
AIM: Write a program for congestion control using leaky bucket algorithm.
SOURCE CODE:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#define BUCKET_SIZE 100
#define OUTPUT_RATE 10
void leakyBucket(int inputRate, int duration)
{
int bucketSize = BUCKET_SIZE;
int outputRate = OUTPUT_RATE;
int packetSize, i;
printf("Simulation Start\n");
for (i = 0; i < duration; i++)
{
printf("\nSecond %d:\n", i + 1);
packetSize = rand() % inputRate;
printf("Incoming packet size: %d\n", packetSize);
if (packetSize <= bucketSize)
{
bucketSize -= packetSize;
printf("Bucket output successful\n");
}
else
{
printf("Bucket overflow - Packet discarded\n");
}
printf("Bucket size after operation: %d\n", bucketSize);
sleep(1);
OUTPUT:
Enter input rate (in Bytes/Second): 50
Enter duration of simulation (in seconds): 5
Simulation Start
Second 1:
Incoming packet size: 33
Bucket output successful
Bucket size after operation: 67
Bucket size after output: 77
Second 3:
Incoming packet size: 27
Bucket output successful
Bucket size after operation: 24
Bucket size after output: 34
Second 4:
Incoming packet size: 15
Bucket output successful
Bucket size after operation: 19
Bucket size after output: 29
Second 5:
Incoming packet size: 43
Bucket overflow - Packet discarded
Bucket size after operation: 29
Bucket size after output: 39
Simulation End
Experiment-10
AIM: Write a Program to implement Dijkstra‘s algorithm to compute the Shortest
path through a graph.
SOURCE CODE:
#include<stdio.h>
int graph[10][10], source, n, mark[10], pe[10], pred[10], count = 0, u, v, i, j;
void printpath(int, int, int[]);
int min(int[], int[], int);
int main()
{
printf("\nEnter number of vertices: ");
scanf("%d", &n);
printf("\nEnter the adjacency matrix:\n");
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &graph[i][j]);
}}
printf("\nEnter the source vertex: ");
scanf("%d", &source);
for (j = 1; j <= n; j++) {
mark[j] = 0;
pe[j] = 999;
pred[j] = 0;
}
pe[source] = 0;
while (count < n)
{
u = min(pe, mark, n);
mark[u] = 1;
for (i = 1; i <= n; i++)
OUTPUT:
Enter number of vertices: 5
Enter the adjacency matrix:
01020
10536
05047
23400
06700
Experiment-11
AIM: Write a Program to implement Distance vector routing algorithm by
obtaining routing table at each node.
(Take an example subnet graph with weights indicating delay between nodes).
SOURCE CODE:
#include<stdio.h>
int main()
{
int n, na, min, i, j, tdel[10][10], del[10];
char ch, adj[10];
printf("Enter the no. of vertices: ");
scanf("%d", &n);
printf("Enter the no. of adjacent vertices: ");
scanf("%d", &na);
for (i = 0; i < na; i++)
{
printf("Enter the name of the vertex and time delay: ");
scanf(" %c%d", &adj[i], &del[i]);
}
for (i = 0; i < na; i++) {
printf("Enter the delay from adjacent vertex %c to all other vertices: ", adj[i]);
for (j = 0; j < n; j++) {
scanf("%d", &tdel[i][j]);
}
}
printf("SNO.\tDIST\tLINE\n");
for (i = 0; i < n; i++) {
min = 1000;
ch = 'a';
for (j = 0; j < na; j++) {
OUTPUT:
Enter the no. of vertices: 9
Enter the no. of adjacent vertices: 3
Enter the name of the vertex and time delay: A
1
Enter the name of the vertex and time delay: C
1
Enter the name of the vertex and time delay: E
3
Enter the delay from adjacent vertex A to all other vertices: 3
3
7
8
7
6
5
9
8
Experiment-12
AIM: Write a Program to implement Broadcast tree by taking subnet of hosts.
SOURCE CODE:
#include<stdio.h>
struct ed
{
int v1, v2, w;
} edj[20], temp;
int main()
{
int i, j, n = 0, s, d, par[20], s1, d1;
printf("\nEnter number of edges: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("\nEnter the node1, node2, weights for edge %d: ", i + 1);
scanf("%d %d %d", &edj[i].v1, &edj[i].v2, &edj[i].w);
par[i] = 0;
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n - i - 1; j++)
{
if (edj[j].w > edj[j + 1].w)
{
temp = edj[j];
edj[j] = edj[j + 1];
edj[j + 1] = temp;
}
}
OUTPUT:
Enter number of edges: 5
Enter the node1, node2, weights for edge 1: 4 5 2
Enter the node1, node2, weights for edge 2: 5 1 3
Enter the node1, node2, weights for edge 3: 1 2 4
Enter the node1, node2, weights for edge 4: 2 3 9
Enter the node1, node2, weights for edge 5: 3 4 10
Experiment-13
AIM: Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters
2.Use the Wireless Toolbar to configure the desired channel and channel width.
Note: If the AirPcap isn't listed, press F5 to refresh the list of available
Note: .Pcap and .Pcap-ng are good filetypes to use for the capture if you plan to use Eye P.A.
to open the capture.
Wireshark is a network packet analyzer. A network packet analyzer presents captured packet
data in as much detail as possible. You could think of a network packet analyzer as a measuring
device for examining what’s happening inside a network cable, just like an electrician uses a
voltmeter for examining what’s happening inside an electric cable
Here are some reasons people use Wireshark:
Simply install Win10Pcap on your Windows PC, either before or after your favorited WinPcap-
compatible applications (e.g. Wireshark).
Since Win10Pcap has the binary-compatibility with the original WinPcap DLLs, Wireshark will
begin to work in Windows 10 immediately after installing Win10Pcap.
Options Ctrl+K configure interfaces and capture options. See section “The
“Capture Options” Dialog Box”.
Start Ctrl+E Immediately starts capturing packets with the same settings
as the last time.
Stop Ctrl+E Stops the currently running capture. See Section “Stop the
running capture”.
Restart Ctrl+R Stops the currently running capture and starts it again with
the same options.
Shows a dialog box that allows you to create and edit capture
__ filters. You can name filters and save them for future use. See
Capture Filters
Section “Defining And Saving Filters”.
Display Filters and edit display filters. You can name filters, and
you can save them for future use. See Section 6.6,
“Defining And Saving Filters”.
Display Filter Macros edit display filter macros. You can name filter
macros, and you can save them for future use. See
Section 6.7, “Defining And Saving Filter Macros”.
Apply as Column Shift+Ctrl+I Adds the selected protocol item in the packet
details pane as a column to the packet list.
Follow → TCP Stream captured that are on the same TCP connection as a
selected packet. See Section 7.2, “Following
Protocol Streams”.
Follow → TLS Stream but for TLS or SSL streams. See the wiki page
on TLS for instructions on providing TLS
keys.
Capture File Properties Show information about the capture file, see Section 8.2,
“The “Capture File Properties” Dialog”.
Resolved Addresses See Section 8.3, “Resolved Addresses”
Experiment-14
AIM: How to run Nmap scan.
Nmap is a network mapper that has emerged as one of the most popular, free network discovery
tools on the market. Nmap is now one of the core tools used by network administrators to map
their networks. The program can be used to find live hosts on a network, perform port scanning,
ping sweeps, OS detection, and version detection.
What is Nmap?
At its core, Nmap is a network scanning tool that uses IP packets to identify all the devices
connected to a network and to provide information on the services and operating systems they
are running.
At a practical level, Nmap is used to provide detailed, real-time information on your networks,
and on the devices connected to them. The primary uses of Nmap can be broken into three core
processes. First, the program gives you detailed information on every IP active on your
networks, and each IP can then be scanned. This allows administrators to check whether an IP
is being used by a legitimate service, or by an external attacker.
Secondly, Nmap provides information on your network as a whole. It can be used to provide a
list of live hosts and open ports, as well as identifying the OS of every connected device. This
makes it a valuable tool in ongoing system monitoring, as well as a critical part of pen testing.
This makes it a valuable tool in ongoing system monitoring, as well as a critical part of
pentesting. Nmap can be used alongside the Metasploit framework, for instance, to probe and
then repair network vulnerabilities.
Thirdly, Nmap has also become a valuable tool for users looking to protect personal and business
websites. Using Nmap to scan your own web server, particularly if you are hosting your website
from home, is essentially simulating the process that a hacker would use to attack your site.
“Attacking” your own site in this way is a powerful way of identifying security vulnerabilities.
This command then returns a list of hosts on your network and the total number of assigned IP
addresses. If you spot any hosts or IP addresses on this list that you cannot account for, you can
then run further commands (see below) to investigate them further.
This returns information on every host, their latency, their MAC address, and also any
description associated with this address. This can be a powerful way of spotting suspicious hosts
connected to your network.
Nmap Commands:
There are several ways to execute port scanning using Nmap. The most commonly used are
these:
# sS TCP SYN scan
# sU UDP scans
# sN TCP NULL
Ping Scanning
As mentioned above, a ping scan returns information on every active IP on your network.
You can execute a ping scan using this command:
Port Scanning
Host Scanning
Host scanning returns more detailed information on a particular host or a range of IP addresses.
As mentioned above, you can perform a host scan using the following command:
OS Scanning
OS scanning is one of the most powerful features of Nmap. When using this type of scan, Nmap
sends TCP and UDP packets to a particular port, and then analyze its response. It compares this
response to a database of 2600 operating systems, and return information on the OS (and version)
of a host.
If you are running Nmap on a home server, this command is very useful. It automatically scans
a number of the most ‘popular’ ports for a host. You can run this command using:
Replace the “20” with the number of ports to scan, and Nmap quickly scans that many ports. It
returns a concise output that details the status of the most common ports, and this lets you
quickly see whether you have any unnecessarily open ports.
Output to a File
If you want to output the results of your Nmap scans to a file, you can add an extension to your
commands to do that. Simply add:
-oN output.txt
To your command to output the results to a text file, or: -oX output.xml To output to n XML.
Finally, you can speed up your Nmap scans by using the -n parameter to disable reverse DNS
resolution. This can be extremely useful if you want to scan a large network. For example, to
turn off DNS resolution for the basic ping scan mentioned above, add -n:
Experiment-15
AIM: Operating System Detection using Nmap.
OS Scanning
OS scanning is one of the most powerful features of Nmap. When using this type of scan, Nmap sends
TCP and UDP packets to a particular port, and then analyze its response. It compares this response to
a database of 2600 operating systems, and return information on the OS (and version) of a host.
Simply add -O to your scan options. You may want to also increase the verbosity with - v for
even more OS-related details. This is shown in Example
#nmap -O -v scanme.nmap.org
Starting Nmap ( http://nmap.org )
Nmap scan report for scanme.nmap.org
Experiment-16
AIM: Do the following using NS2 Simulator
i. NS2 Simulator-Introduction.
ii. Simulate to Find the Number of Packets Dropped.
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP.
iv. Simulate to Find the Number of Packets Dropped due to Congestion.
v. Simulate to Compare Data Rate& Throughput.
What is NS2:
NS2 simulator is a piece of software or hardware used to predict the performance of overall
network.
Supports a number of algorithms for Queuing and Routing and used to verify the viability
of new algorithms, check topologies, test architectures etc.
Discrete event simulator used for the simulation of routing protocols and are at present
heavily used in ad-hoc networking research.
It supports wide range of network protocols and provide simulation environment for both
wired and wireless networks.
Implementation of NS2: