CN Lab Manual
CN Lab Manual
SCHOOL OF ENGINEERING
PRACTICAL RECORD
Course:______________Branch:____________Reg.No:______________________
Name of Laboratory:___________________________________________________
ST.MARY’S GROUP OF INSTITUTIONS GUNTUR
(Approved by AICTE &Govt .of AP, Affiliated to JNTU-KAKINADA, Accredited by 'NAAC')
Chebrolu (V&M), Guntur (Dist), Andhra Pradesh, INDIA-522212
SCHOOL OF ENGINEERING
Certificate
This is to certify that Mr. / Ms.
academic year .
Signature of HOD
Index
Signature of
S.No Name of the Program Page No. Date
the Faculty
COMPUTER NETWORKS LAB MANUAL
List of Experiments:
1. Study of Network devices in detail and connect the computers in Local Area Network.
2. Write a Program to implement the data link layer farming methods such as
i) Character stuffing ii) bit stuffing.
3. Write a Program to implement data link layer farming method checksum.
4. Write a program for Hamming Code generation for error detection and correction.
5. Write a Program to implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC
CCIP.
6. Write a Program to implement Sliding window protocol for Goback N.
7. Write a Program to implement Sliding window protocol for Selective repeat.
8. Write a Program to implement Stop and Wait Protocol.
Aim: Study of different types of Network cables and Practically implement the cross -wiredcable and straight
through cable using clamping tool.
1. Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very careful at this point,
as to not nick or cut into the wires, which are inside. Doing so could alter the characteristics of your cable, or even
worse render is useless. Check the wires, one more time for nicks or cuts. If there are any, just whack the whole
end off, and start over.
2. Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand. You do not want the
wires to become untwisted down inside the jacket. Category 5 cable must only have 1/2 of an inch of 'untwisted'
wire at the end; otherwise it will be 'out of spec'.At this point, you obviously have ALOT more than 1/2 of an
inch of un-twisted wire.
3. You have 2 end jacks, which must be installed on your cable. If you are using a pre-made cable, with one of
the ends whacked off, you only have one end to install - the crossed over end. Below are two diagrams, which
show how you need to arrange the cables for each type of cable end. Decide at this point which end you are
making and examine the associated picture below.
Diagram shows you how to prepare Cross wired connection
Diagram shows you how to prepare straight through wired connection
1. Repeater:Functioning at Physical Layer.A repeater is an electronic device that receives a signal and
retransmits it at a higher level and/or higher power, or onto the other side of an obstruction, so that the signal
can cover longer distances. Repeater have two ports ,so cannotbe use to connect for more than two devices
2. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator
is a device for connecting multiple twisted pair or fiber optic Ethernet devices together and making them act as
a single network segment. Hubs work at the physical layer (layer 1) of the OSI model. The device is a form of
multiport repeater. Repeater hubs also participate in collision detection, forwarding a jam signal to all ports if it
detects a collision.
3. Switch:A network switch or switching hub is a computer networking device that connects network
segments.The term commonly refers to a network bridge that processes androutes data at the data link layer (layer
2) of the OSI model. Switches that additionally process data at the network layer (layer 3 and above) are often
referred to as Layer 3 switches or multilayer switches.
4. Bridge: A network bridge connects multiple network segments at the data link layer (Layer 2) of the OSI
model. In Ethernet networks, the term bridge formally means a device that behaves according to the IEEE
802.1D standard. A bridge and switch are very much alike; a switch being a bridge with numerous ports. Switch
or Layer 2 switch is often used interchangeably with bridge.Bridges can analyze incoming data packets to
determine if the bridge is able to send the given packet to another segment of the network.
5. Router: A router is an electronic device that interconnects two or more computer networks, and selectively
interchanges packets of data between them. Each data packet contains address information that a router can use
to determine if the source and destination are on the same network, or if the data packet must be transferred from
one network to another. Where multiple routers are used in a large collection of interconnected networks, the
routers exchange information about target system addresses, so that each router can build up a table showing the
preferred paths between any two systems on the interconnected networks.
6. Gate Way: In a communications network, a network node equipped for interfacing with another network that uses different
protocols.
• A gateway may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It also
requires the establishment of mutually acceptable administrative procedures between both networks.
• A protocol translation/mapping gateway interconnects networks with different network protocol
technologies by performing the required protocol conversions.
EXPERIMENT 2
Write a Program to implement the data link layer farming methods such as
i) Character stuffing ii) bit stuffing.
#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("Enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("Enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);}
printf("Enter the character\n");
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
}
Program Output:
Enter string
MLRITM
Enter position
2
Enter the character
frame after stuffing:
dlestxMdldleLRITMdleetx
------------------
Program Code: // BIT Stuffing program
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
Program 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
Write a Program to implement data link layer farming method checksum.
The Checksum is an error detection method that detected errors in data/message while it is transmitted from sender to receiver.
This method is used by the higher layer protocols and makes use of the Checksum Generator on the Sende r side and Checksum
Checker on the Receiver side.
Examples:
Input: sent_message = “10101111”, rec_message = “10101101”, block_size = 8
Output: Error
Explaination: Since the 7th bit in the sent_message and the rec_message is different, the final checksum value is not equal to
zero denoting that some error has occurred during transmission.
Input: sent_message = “10000101011000111001010011101101”, rec_message = “10000101011000111001010011101101”,
block_size = 8
Output: No Error
#include <bits/stdc++.h>
if (data[i] == '0')
data[i] = '1';
else
data[i] = '0';
return data;
int n = data.length();
if (n % block_size != 0) {
result += data[i];
next_block += data[j];
carry = sum / 2;
if (sum == 0) {
sum = carry;
else if (sum == 1) {
sum = carry;
else if (sum == 2) {
sum = carry;
else {
sum = carry;
if (carry == 1) {
if (carry == 0) {
== 0) {
carry = 1;
else {
carry = 0;
result = final;
else {
result = additions;
return Ones_complement(result);
}
// Function to check if the received message
string rec_message,
int block_size)
string sender_checksum
= checkSum(sent_message, block_size);
if (count(receiver_checksum.begin(),
receiver_checksum.end(), '0')
== block_size) {
return true;
else {
return false;
}
// Driver Code
int main()
string sent_message
= "10000101011000111001010011101101";
string recv_message
= "10000101011000111001010011101101";
int block_size = 8;
if (checker(sent_message,
recv_message,
block_size)) {
else {
return 0;
Output
No Error
EXPERIMENT 4
Write a program for Hamming Code generation for error detection and correction
#include <stdio.h>
int input[32];
int code[32];
// ith position
int count = 0, i, j;
i = position - 1;
// If current boit is 1
if (code[j] == 1)
count++;
// Update i
i = i + 2 * position;
if (count % 2 == 0)
return 0;
else
return 1;
i = 0;
p_n++;
i++;
}
c_l = p_n + n;
j = k = 0;
if (i == ((int)pow(2, k) - 1)) {
code[i] = 0;
k++;
else {
code[i] = input[j];
j++;
// hamming code
code[position - 1] = value;
printf("%d", code[i]);
// Driver Code
void main()
input[0] = 0;
input[1] = 1;
input[2] = 1;
input[3] = 1;
int N = 4;
// Function Call
solve(input, N);
Output:
The generated Code Word is: 0001111
EXPERIMENT 5
Write a Program to implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and
CRC CCIP
Program Code: // Program for Cyclic Redundency Check
#include<stdio.h>
int gen[4],genl,frl,rem[4];
void main()
{
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
frl=8; genl=4;
printf("Enter frame:");
for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
}
printf("Enter generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);
tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
{
dupfr[i]=0;
}
remainder(dupfr);
for(i=0;i<frl;i++)
{
recfr[i]=fr[i];
}
for(i=frl,j=1;j<genl;i++,j++)
{
recfr[i]=rem[j];
}
remainder(recfr);
flag=0;
for(i=0;i<4;i++)
{
if(rem[i]!=0)
flag++;
}
if(flag==0)
{
printf("frame received correctly");
}
else
{
printf("the received frame is wrong");
}
}
remainder(int fr[])
{
int k,k1,i,j;
for(k=0;k<frl;k++)
{
if(fr[k]==1)
{
k1=k;
for(i=0,j=k;i<genl;i++,j++)
{
rem[i]=fr[j]^gen[i];
}
for(i=0;i<genl;i++)
{
fr[k1]=rem[i];
k1++;
}
}
}
}
Program Output:
Enter frame: MLRITM
Enter generator: frame received correctly
------------------
EXPERIMENT 6
Write a Program to implement Sliding window protocol for Goback N
CODE
#include<bits/stdc++.h>
#include<ctime>
int main() {
ll tf, N, tt = 0;
srand(time(NULL));
cout << “Enter the Total number of frames : “;
cin >> tf;
cout << “Enter the Window Size : “;
cin >> N;
ll I = 1;
transmission(I, N, tf, tt);
cout << “Total number of frames which were sent and resent are : “ << tt <<
endl;
return 0;
}
OUTPUT:
Sending Frame 1…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Acknowledgment for Frame 1…
Timeout!! Frame Number : 2 Not Received
Retransmitting Window…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Sending Frame 5…
Timeout!! Frame Number : 2 Not Received
Retransmitting Window…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Sending Frame 5…
Acknowledgment for Frame 2…
Acknowledgment for Frame 3…
Acknowledgment for Frame 4…
Timeout!! Frame Number : 5 Not Received
Retransmitting Window…
Sending Frame 5…
Sending Frame 6…
Sending Frame 7…
Sending Frame 8…
Timeout!! Frame Number : 5 Not Received
Retransmitting Window…
Sending Frame 5…
Sending Frame 6…
Sending Frame 7…
Sending Frame 8…
Acknowledgment for Frame 5…
Timeout!! Frame Number : 6 Not Received
Retransmitting Window…
Sending Frame 6…
Sending Frame 7…
Sending Frame 8…
Sending Frame 9…
Acknowledgment for Frame 6…
Timeout!! Frame Number : 7 Not Received
Retransmitting Window…
Sending Frame 7…
Sending Frame 8…
Sending Frame 9…
Sending Frame 10…
Acknowledgment for Frame 7…
Acknowledgment for Frame 8…
Acknowledgment for Frame 9…
Acknowledgment for Frame 10…
EXPERIMENT 7
Write a Program to implement Sliding window protocol for Selective repeat
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of
frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}
Output
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver
12 5 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender
EXPERIMENT 8
Write a Program to implement Stop and Wait Protocol
#include<iostream>
#include <time.h>
#include <cstdlib>
#include<ctime>
#include <unistd.h>
using namespace std;
class timer {
private:
unsigned long begTime;
public:
void start() {
begTime = clock();
}
unsigned long elapsedTime() {
return ((unsigned long) clock() - begTime) / CLOCKS_PER_SEC;
}
bool isTimeout(unsigned long seconds) {
return seconds >= elapsedTime();
}
};
int main()
{
int frames[] = {1,2,3,4,5,6,7,8,9,10};
unsigned long seconds = 5;
srand(time(NULL));
timer t;
cout<<"Sender has to send frames : ";
for(int i=0;i<10;i++)
cout<<frames[i]<<" ";
cout<<endl;
int count = 0;
bool delay = false;
cout<<endl<<"Sender\t\t\t\t\tReceiver"<<endl;
do
{
bool timeout = false;
cout<<"Sending Frame : "<<frames[count];
cout.flush();
cout<<"\t\t";
t.start();
if(rand()%2)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
}
if(t.elapsedTime() <= seconds)
{
cout<<"Received Frame : "<<frames[count]<<" ";
if(delay)
{
cout<<"Duplicate";
delay = false;
}
cout<<endl;
count++;
}
else
{
cout<<"---"<<endl;
cout<<"Timeout"<<endl;
timeout = true;
}
t.start();
if(rand()%2 || !timeout)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
if(t.elapsedTime() > seconds )
{
cout<<"Delayed Ack"<<endl;
count--;
delay = true;
}
else if(!timeout)
cout<<"Acknowledgement : "<<frames[count]-1<<endl;
}
}while(count!=10);
return 0;
}
OUTPUT
Sender has to send frames : 1 2 3 4 5 6 7 8 9 10
Sender Receiver
Sending Frame : 1 Received Frame : 1
Acknowledgement : 1
Sending Frame : 2 ---
Timeout
Sending Frame : 2 Received Frame : 2
Acknowledgement : 2
Sending Frame : 3 Received Frame : 3
Acknowledgement : 3
Sending Frame : 4 Received Frame : 4
Acknowledgement : 4
Sending Frame : 5 Received Frame : 5
Acknowledgement : 5
Sending Frame : 6 Received Frame : 6
Acknowledgement : 6
Sending Frame : 7 Received Frame : 7
Delayed Ack
Sending Frame : 7 Received Frame : 7 Duplicate
Delayed Ack
Sending Frame : 7 ---
Timeout
Sending Frame : 7 Received Frame : 7 Duplicate
Acknowledgement : 7
Sending Frame : 8 ---
Timeout
Delayed Ack
Sending Frame : 7 Received Frame : 7
Acknowledgement : 7
Sending Frame : 8 Received Frame : 8
Acknowledgement : 8
Sending Frame : 9 Received Frame : 9
Delayed Ack
Sending Frame : 9 ---
Timeout
Sending Frame : 9 Received Frame : 9 Duplicate
Delayed Ack
Sending Frame : 9 Received Frame : 9 Duplicate
Acknowledgement : 9
Sending Frame : 10 ---
Timeout
Sending Frame : 10 Received Frame : 10
Acknowledgement : 10
EXPERIMENT 9
Write a program for congestion control using leaky bucket algorithm
#include <bits/stdc++.h>
int main()
storage = 0;
bucket_size = 10;
input_pkt_size = 4;
output_pkt_size = 1;
// update storage
storage += input_pkt_size;
else {
storage, bucket_size);
storage -= output_pkt_size;
return 0;
}
Output
EXPERIMENT 10
Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path through a graph
#include <limits.h>
#include <stdio.h>
#define V 9
int minDistance(int dist[], bool sptSet[]) {
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v], min_index = v;
return min_index;
}
int printSolution(int dist[], int n) {
printf("Vertex Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t %d\n", i, dist[i]);
}
void dijkstra(int graph[V][V], int src) {
int dist[V];
bool sptSet[V];
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;
dist[src] = 0;
for (int count = 0; count < V - 1; count++) {
int u = minDistance(dist, sptSet);
sptSet[u] = true;
for (int v = 0; v < V; v++)
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] + graph[u][v] < dist[v]) dist[v] = dist[u] +
graph[u][v];
}
printSolution(dist, V);
}
int main() {
int graph[V][V] = { { 0, 6, 0, 0, 0, 0, 0, 8, 0 },
{ 6, 0, 8, 0, 0, 0, 0, 13, 0 },
{ 0, 8, 0, 7, 0, 6, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 6, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 13, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 }
};
dijkstra(graph, 0);
return 0;
}
Output
Vertex Distance from Source
00
16
2 14
3 21
4 21
5 11
69
78
8 15
EXPERIMENT 11
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).
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct distance from the node i to k
using the cost matrix
//and add the distance from k to node j
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{//We calculate the minimum distance
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
/*OUTPUT
A sample run of the program works as:-
Enter the number of nodes :
3
Enter the cost matrix :
027
201
710
For router 1
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
For router 2
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
For router 3
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0
EXPERIMENT 12
Write a Program to implement Broadcast tree by taking subnet of hosts
#include
int a[10][10],n;
main()
{
int i,j,root;
clrscr();
printf(“Enter no.of nodes:”);
scanf(“%d”,&n);
printf(“Enter adjacent matrix\n”);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf(“Enter connecting of %d–>%d::”,i,j);
scanf(“%d”,&a[i][j]);
}
printf(“Enter root node:”);
scanf(“%d”,&root);
adj(root);
}
adj(int k)
{
int i,j;
printf(“Adjacent node of root node::\n”);
printf(“%d\n\n”,k);
for(j=1;j<=n;j++)
{
if(a[k][j]==1 || a[j][k]==1)
printf(“%d\t”,j);
}
printf(“\n”);
for(i=1;i<=n;i++)
{
if((a[k][j]==0) && (a[i][k]==0) && (i!=k))
printf(“%d”,i);
}
}
OUTPUT
Enter no.of nodes:5
Enter adjacent matrix
Enter connecting of 1–>1::0
Enter connecting of 1–>2::1
Enter connecting of 1–>3::1
Enter connecting of 1–>4::0
Enter connecting of 1–>5::0
Enter connecting of 2–>1::1
Enter connecting of 2–>2::0
Enter connecting of 2–>3::1
Enter connecting of 2–>4::1
Enter connecting of 2–>5::0
Enter connecting of 3–>1::1
Enter connecting of 3–>2::1
Enter connecting of 3–>3::0
Enter connecting of 3–>4::0
Enter connecting of 3–>5::0
Enter connecting of 4–>1::0
In the CSC 4190 Introduction to Computer Networking, TCP/IP network stack is introduced and studied. This background
section briefly explains the concept of TCP/IP network stack to help you better understand the experiments. TCP/IP is the
most commonly used network model for Internet services. Because its most important protocols, the Transmission Control
Protocol (TCP) and the Internet Protocol (IP) were the first networking protocols defined in this standard, it is named as
TCP/IP. However,it contains multiple layers including application layer, transport layer, network layer, and data link layer.
- Application Layer: The application layer includes the protocols used by most applications for providing
user services. Examples of application layer protocols are Hypertext Transfer Protocol (HTTP), Secure
Shell (SSH), File Transfer Protocol (FTP), and Simple Mail Transfer Protocol (SMTP).
- Transport Layer: The transport layer establishes process-to-process connectivity,and it provides end-to-
end services that are independent of underlying user data. To implement the process-to-process
communication, the protocol introduces a concept of port. The examples of transport layer protocols are
Transport Control Protocol (TCP) and User Datagram Protocol (UDP). The TCP provides flow- control,
connection establishment, and reliable transmission of data, while the UDP is a connectionless
transmission model.
- Internet Layer: The Internet layer is responsible for sending packets to across networks. It has two
functions: 1) Host identification by using IP addressing system (IPv4 and IPv6); and 2) packets routing
from source to destination. The examples of Internet layer protocols are Internet Protocol (IP), Internet
Control Message Protocol (ICMP), and Address Resolution Protocol (ARP).
- Link Layer: The link layer defines the networking methods within the scope of thelocal network link. It
is used to move the packets between two hosts on the samelink. An common example of link layer
protocols is Ethernet.
Packet Sniffer
Packet sniffer is a basic tool for observing network packet exchanges in a computer. As the name suggests, a packet sniffer
captures (“sniffs”) packets being sent/received from/by your computer; it will also typically store and/or display the
contents of the various protocol fields in these captured packets. A packet sniffer itself is passive. It observes messages
being sent and received by applications and protocols running on your computer, but never sends packets itself.
Figure 3 shows the structure of a packet sniffer. At the right of Figure 3 are the protocols (in this case, Internet protocols)
and applications (such as a web browser orftp client) that normally run on your computer. The packet sniffer, shown
within the dashed rectangle in Figure 3 is an addition to the usual software in your computer, and consists of two parts.
The packet capture library receives a copy of every link-layer frame that is sent from or received by your computer.
Messages exchanged by higher layer protocols such as HTTP, FTP, TCP, UDP, DNS, or IP all are eventually encapsulated
in link-layer frames that are transmitted over physical media such as an Ethernet cable. In Figure 1, the assumed physical
media is an Ethernet, and so all upper-layer protocols are eventually encapsulated within an Ethernet frame. Capturing all
link-layer frames thus gives you access to all messages sent/received from/by all protocols and applications executing in
your computer.
The second component of a packet sniffer is the packet analyzer, which displays the contents of all fields within a protocol
message. In order to do so, the packet analyzer
must “understand” the structure of all messages exchanged by protocols. For example, suppose we are interested in
displaying the various fields in messages exchanged by the HTTP protocol in Figure 3. The packet analyzer understands
the format of Ethernet frames, and so can identify the IP datagram within an Ethernet frame. It also understands the IP
datagram format, so that it can extract the TCP segment within the IP datagram. Finally, it understands the TCP segment
structure, so it can extract the HTTP message contained in the TCP segment. Finally, it understands the HTTP protocol
and so, for example, knows that the first bytes of an HTTP message willcontain the string “GET,” “POST,” or
“HEAD”.
We will be using the Wireshark packet sniffer [http://www.wireshark.org/] for these labs, allowing us to display the
contents of messages being sent/received from/by protocolsat different levels of the protocol stack. (Technically speaking,
Wireshark is a packet analyzer that uses a packet capture library in your computer). Wireshark is a free network protocol
analyzer that runs on Windows, Linux/Unix, and Mac computers.
Getting Wireshark
The Kai Linux has Wireshark installed. You can just launch the Kali Linux VM and openWireshark there. Wireshark
can also be downloaded from here:
https://www.wireshark.org/download.html
Starting Wireshark
When you run the Wireshark program, the Wireshark graphic user interface will be shown as Figure 5. Currently, the
program is not capturing the packets.
Figure 5: Initial Graphic User Interface of Wireshark
Then, you need to choose an interface. If you are running the Wireshark on your laptop,you need to select WiFi interface.
If you are at a desktop, you need to select the Ethernet interface being used. Note that there could be multiple interfaces.
In general, you can select any interface but that does not mean that traffic will flow through that
interface. The network interfaces (i.e., the physical connections) that your computer hasto the network are shown. The
attached Figure 6 was taken from my computer.
After you select the interface, you can click start to capture the packets as shown in
Figure 7.
After downloading and installing Wireshark, you can launch it and click the name of an interface under Interface List to
start capturing packets on that interface. For example, ifyou want to capture traffic on the wireless network, click your
wireless interface.
Test Run
Do the following steps:
1. Start up the Wireshark program (select an interface and press start to capture packets).
2. Start up your favorite browser (ceweasel in Kali Linux).
3. In your browser, go to Wayne State homepage by typing www.wayne.edu.
4. After your browser has displayed the http://www.wayne.edu page, stop Wireshark packet capture by
selecting stop in the Wireshark capture window.This will cause the Wireshark capture window to
disappear and the main Wireshark window to display all packets captured since you began packet
capture see image below:
5.Color Coding: You’ll probably see packets highlighted in green, blue, and black. Wireshark uses colors
to help you identify the types of traffic at a glance. By default, green is TCP traffic, dark blue is DNS
traffic, light blue is UDP traffic, andblack identifies TCP packets with problems — for example, they
could have beendelivered out-of-order.
6.You now have live packet data that contains all protocol messages exchanged between your computer and
other network entities! However, as you will notice the HTTP messages are not clearly shown because
there are many other packets included in the packet capture. Even though the only action you took
was to open your browser, there are many other programs in your computer that communicate via the
network in the background. To filter the connections to the ones we want to focus on, we have to use
the filtering functionality of Wireshark by typing “http” in the filtering field as shown below:
Notice that we
now view only the packets that are of protocol HTTP. However, we also still do not have the exact communication we
want to focus on because using HTTP as a filter is not descriptive enough to allow us to find our connection to
http://www.wayne.edu. We need to be more precise if we want to capture the correct setof packets.
7.To further filter packets in Wireshark, we need to use a more precise filter. By setting the
http.host==www.wayne.edu, we are restricting the view to packets that have as an http host the
www.wayne.edu website. Notice that we need two equal signs to perform the match “==” not just one. See
the screenshot below:
8.Now, we can try another protocol. Let’s use Domain Name System (DNS) protocol as an example
here.
9.Let’s try now to find out what are those packets contain by following one of the conversations (also
called network flows), select one of the packets and pressthe right mouse button (if you are on a Mac
use the command button and click), you should see something similar to the screen below:
EXPERIMENT 14
How to run Nmap scan
Nmap is a free and open-source utility which is used to scan networks and security auditing. Nmap can discover hosts and
services on a computer network by sending packets and analyzing the responses. The utility is available on almost every os, i t is
available for windows, linux and mac.
Download Nmap –
To download Nmap you can simply head towards the official website by clicking here. In case of kali Linux and parrot os, it is
already available in there so you will not need to download the utility.
Please note that scanning websites from Nmap is not legal, in some cases if you are trying to too much in deep then you will
need written permissions from the owner of the website and the IP holder.
In Windows hosts you can simply install nmap and run it from the desktop icon using administrator privileges . In linux hosts
there are 2 ways of doing it, in case of kali linux and parrot os you can find the icon and click to start and later give it root
privileges by entering your password .
As already mentioned, scanning networks and websites using nmap can be illegal, you may need written permissions to so. So, to
do scans that are legal you can use scanme.org, they offer you to perform scans on their website without any issues, but please
read their conditions so that you do not harm their website.
Now lets see a simple example to do a scan. To do so simply use nslookup command following the website url or address. If you
do not know the IP address of the website and using the command.
nslookup scanme.nmap.org
will give you its address. Now when you get the address you can use the same for scanning the network by
nslookup "address"
the address should be written as IP address which you found on the previous scan and without quotes.
This is how you can do a simple network scan. Now you can also save your scans in a text file for simplicity by using the
command
nslookup 45.33.32.156 >> result.txt
Please note that nmap is a very noisy scanning utility and you need to be anonymous and legal in some cases to do so. Please
ensure that you use it for legal and educational purposes.
EXPERIMENT 15
Operating System Detection using Nmap
NMAP stands for Network Mapper which is an open-source tool used for network exploration and security auditing, in
comparison to this, a tool named Nessus is used by industry professionals. These tools are mainly used by cybersecurity experts
and hackers.
Its main purpose is:
• Provide the list of the live host.
• Find the open Ports.
• The real-time information of a network.
• OS and Port scanning.
The hackers and the cybersecurity expert need to know the Operating System of the machine. It becomes very easy to access a
system if we can know the specific open ports or the security holes of the system. Network Mapper(NMAP) NMAP has a
database that helps in Operating systems (OS) but it is not automatically updated. The database to detect an OS is located at
‘/usr/share/nmap/nmap-os-db’.
Operating System(OS) detection is a very long and hectic process. So, before we get our hands dirty we should know about the
five separate probes being performed to determine the OS. This probe may consist of one or more packets. The response to each
packet (which is sent by the probe) by the target system helps to determine the OS type.
The five different probes are:
• Sequence Generation.
• ICMP Echo.
• TCP Explicit Congestion Notification.
• TCP.
• UDP.
1. Sequence Generation: The Sequence Generation Probe consists of six packets that are sent 100 ms apart and are all TCP
SYN packets. The result of all these packets will help in Operating System(OS) detection.
2. ICMP Echo: Two ICMP request packets are sent to the target system with different settings in the packet. The result of all
these will help verify the OS type by NMAP.
3. TCP Explicit Congestion Notification: Congestion is a slowdown that occurs when a lot of packets are generated and passed
by a single router. The packets which are sent are mainly used to get back the responses from the target system. This helps to
detect the OS because a specific OS returns a specific value and each OS handles a packet differently.
4. TCP: Six packets are sent during this probe, and some packets are sent to open or closed ports with specific packet settings by
using the corresponding result we can determine the type of Operating System(OS). The TCP Packets which are sent with
varying flags are as follows:
• no flags.
• SYN, FIN, URG, and PSH.
• ACK.
• SYN.
• ACK.
• FIN, PSH, and URG.
5. UDP: UDP probe consists of a single packet that is sent to a closed port. If the port used on the target system is closed and an
ICMP Port Unreachable message is returned it specifies that there is no Firewall.
OS detection using NMAP
Now we need to run the actual commands to perform OS detection using NMAP, and at first, we will get the IP address of the
host system, and then will perform a scan to get all active devices on the network.
Step 1: Getting the IP of the System
ifconfig
EXPERIMENT 16
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.
Introduction to NS-2:
NS2 is an open-source simulation tool that runs on Linux. It is a discreet eventsimulator targeted
at networking research and provides substantial support for simulation ofrouting, multicast protocols
and IP protocols, such as UDP, TCP, RTP and SRM overwired and wireless (local and satellite)
networks.
Widely known as NS2, is simply an event driven simulation tool. 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 protocolsand
simulating their corresponding behaviors.
Tcl is a very simple programming language. If you have programmed before, you can learn
enough to write interesting Tcl programs within a few hours. This page providesa quick overview
of the main features of Tcl. After reading this you'll probably be able to start writing simple Tcl scripts
on your own; however, we recommend that you consult one of the many available Tcl books for more
complete information.
Basic syntax
This command computes the sum of 20 and 10 and returns the result, 30. You can try out this
example and all the others in this page by typing them to a Tcl application such as tclsh; after a
command completes, tclsh prints its result.
Each Tcl command consists of one or more words separated by spaces. In this example there
are four words: expr, 20, +, and 10. The first word is the name of a command and the other words are
arguments to that command. All Tcl commands consist of words,
Where do commands come from?
As you have seen, all of the interesting features in Tcl are represented by commands.
Statements are commands, expressions are evaluated by executing commands, control structures are
commands, and procedures are commands.
Tcl commands are created in three ways. One group of commands is provided bythe Tcl
interpreter itself. These commands are called builtin commands. They include all ofthe commands
you have seen so far and many more (see below). The builtin commands are present in all Tcl
applications.
The second group of commands is created using the Tcl extension mechanism. Tcl provides
APIs that allow you to create a new command by writing a command procedure inC or C++ that
implements the command. You then register the command procedure with the Tcl interpreter by
telling Tcl the name of the command that the procedure implements. In the future, whenever that
particular name is used for a Tcl command, Tcl will call your command procedure to execute the
command. The builtin commands are also implemented using this same extension mechanism; their
command procedures are simply part of the Tcllibrary.
When Tcl is used inside an application, the application incorporates its key features into Tcl
using the extension mechanism. Thus the set of available Tcl commands varies from application to
application. There are also numerous extension packages that can be incorporated into any Tcl
application. One of the best known extensions is Tk, which provides powerful facilities for building
graphical user interfaces. Other extensions provideobject-oriented programming, database access,
more graphical capabilities, and a variety of other features. One of Tcl's greatest advantages for
building integration applications is the ease with which it can be extended to incorporate new features
or communicate with other resources.
The third group of commands consists of procedures created with the proc command, such
as the power command created above. Typically, extensions are used for lower-level functions where
C programming is convenient, and procedures are used for higher-level functions where it is easier
to write in Tcl.
Wired TCL Script Components
Features of NS2
NS2 can be employed in most unix systems and windows. Most of the NS2 code is in C++.
It uses TCL as its scripting language, Otcl adds object orientation to TCL.NS(version 2) is an object
oriented, discrete event driven network simulator that is freely distributed and open source.
Structure of NS
● NS is an object oriented discrete event simulator
– Simulator maintains list of events and executes one event after another
– Single thread of control: no locking or race conditions
Source code
Most of NS2 code is in C++
Scripting language
It uses TCL as its scripting language OTcl adds object orientation to TCL.
Start the source applications. Packets are then created and are transmitted through
network.
NS programming Structure
● Create the event scheduler
● Turn on tracing
● Create network topology
proc finish {} {
global ns nf
close $nf
● Start Scheduler
$ns run
Tracing
● Network Animator
set nf [open out.nam w]
$ns namtraceall
$nf
proc finish {} {
global ns nf
close $nf
exec nam out.nam &
exit 0
Creating topology
Data Sending
$cbr0 attach-agent$udp0
● FTP
set ftp [new Application/FTP]
$ftp attach-agent$tcp0
● Telnet
set telnet [new Application/Telnet]
$telnet attach-agent$tcp0
PROCEDURE
STEP 1: Start
STEP 4: Create the nodes of the simulation using the ‘set’ command
attach these agents to the nodes STEP 8: The traffic generator used is
FTP for both node0 and node1