0% found this document useful (0 votes)
18 views52 pages

III-I CN Lab Manual

The document outlines a list of experiments related to data link layer protocols, routing algorithms, and network simulations. It includes implementations for methods like bit stuffing, CRC computation, sliding window protocol, Dijkstra's algorithm, and distance vector routing. Additionally, it provides sample C programs for each experiment to demonstrate their functionality in networking contexts.

Uploaded by

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

III-I CN Lab Manual

The document outlines a list of experiments related to data link layer protocols, routing algorithms, and network simulations. It includes implementations for methods like bit stuffing, CRC computation, sliding window protocol, Dijkstra's algorithm, and distance vector routing. Additionally, it provides sample C programs for each experiment to demonstrate their functionality in networking contexts.

Uploaded by

Anitha Vazzu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 52

List of Experiments

1. Implement the data link layer framing methods such as character,


character-stuffing and bit
stuffing.
2. Write a program to compute CRC code for the polynomials CRC-12,
CRC-16 and CRC CCIP
3. Develop a simple data link layer that performs the flow control
using the sliding window protocol,and loss recovery using the Go-
Back-N mechanism.
4. Implement Dijsktra’s algorithm to compute the shortest path through a
network
5. Take an example subnet of hosts and obtain a broadcast tree for the
subnet.
6. Implement distance vector routing algorithm for obtaining routing tables
at each node.
7. Implement data encryption and data decryption
8. Write a program for congestion control using Leaky bucket algorithm.
9. Write a program for frame sorting techniques used in buffers.
10. Wireshark
i.Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics
& Filters. How to run Nmap
scan
Operating System Detection
using Nmap 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.
vi. Simulate to Plot Congestion for Different Source/Destination
vii.Simulate to Determine the Performance with respect to
Transmission of Packets
1. Implement the data link layer framing methods such
as character, character-stuffing and bit stuffing.
Bit stuffing:
Bit stuffing refers to the insertion of one or more bits into a
data transmission as a way to provide signaling information to a
receiver.
Bit stuffing is a process of inserting an extra bit as 0, once the frame
sequence
encountered 5 consecutive 1's.

Bit Stuffing Program in C:

#include<stdi
o.h>
#include<stri
ng.h> int
main()
{
int
si=0,di=0,count=0
; char
sor[50],des[50];
printf("enter
data:");
scanf("%s",sor);
while(sor[si]!='\0')
{
if(sor[si]=
='1')
count++;
else
count=0;
des[di+
+]=sor[si++];
if(count==5)
{
des[di+
+]='0';
count=0;
}
}
des[di++]='\0';
printf("frame after stuffing=
%s",des); return 0;
}
OUTPUT:
enter data 11111111
frame after stuffing =111110111
BYTE STUFFING
In byte stuffing, a special byte called the escape character (ESC) is
stuffed before every byte in the message with the same pattern as
the flag byte. If the ESC sequence is found in the message byte,
then another ESC byte is stuffed before it.
#include<stdi
o.h>
#include<stri
ng.h> void
main()
{
char frame[50]
[50],str[50][50]; char
flag[10],esc[10];
int i,j,k=0,n;
strcpy(flag,"fla
g");
strcpy(esc,"e
sc");
strcpy(frame[k++],"flag");
printf("Enter no.of String :\
t"); scanf("%d",&n);
printf("Enter
String \n");
for(i=0;i<=n;i++)
{
gets(str[i]);
}
printf("You entered :\n");
for(i=0;i<=n;i++)
{
puts(str[i]);
}
printf("\n");
for(i=1;i<=n
;i++)
{
if(strcmp(str[i],flag)!=0 &&strcmp(str[i],esc)!=0)
{
strcpy(frame[k++],str[i]);
}
else
{
strcpy(frame[k++],"esc");
strcpy(frame[k++],str[i]);
}
}
strcpy(frame[k++],"flag");
//frame[k++]='\0';
printf("-------------------\n");
printf("Byte stuffing at sender
side:\n\n"); printf(" \n");
for(i=0;i<k;i++)
{
printf("%s\t",frame[i]);
}
}
2.Write a program to compute CRC code for the polynomials CRC-12, CRC-16
and CRC CCIP?
This Cyclic Redundancy Check is the most powerful and
easy to implement technique. Unlike checksum scheme,
which is based on addition, CRC is based on binary division.
In CRC, a sequence of redundant bits, called cyclic
redundancy check bits, are appended to the end of data unit
so that the resulting data unit becomes exactly divisible by a
second, predetermined binary number. At the destination,
the incoming data unit is divided by the same number. If at
this step there is no remainder, the data unit is assumed to
be correct and is therefore accepted. A remainder indicates
that the data unit has been damaged in transit and therefore
must be rejected.
#include<stdi
o.h>
#include<stri
ng.h> #define
N strlen(g)

char t[28],cs[28],g[]="1011";
int a,e,c;

void
xorfunction()
{ for(c = 1;c <
N; c++)
cs[c] = (( cs[c] == g[c])?'0':'1');
}

void crc(){
for(e=0;e<N;
e++)
cs[e]=t[
e]; do{
if(cs[0]=='1')
xorfunction();
for(c=0;c<N-
1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
}
int main()
{
printf("\nEnter data : ");
scanf("%s",t);
printf("\n ");
printf("\nGenerating
polynomial : %s",g);
a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n ");
printf("\nPaded data is :
%s",t); printf("\n
")
;
crc();
printf("\nCRC is :
%s",cs);
for(e=a;e<a+N-
1;e++)
t[e]=cs[e-a];
printf("\n ");
printf("\nFinal data to be
sent : %s",t); printf("\n ");
printf("\nTest error detection 0(yes)
1(no)? : "); scanf("%d",&e);
if(e==0)
{
do{
printf("\nEnter the position where error is to be
inserted : "); scanf("%d",&e);
}while(e==0 ||
e>a+N-1); t[e-
1]=(t[e-
1]=='0')?'1':'0';
printf("\n ");
printf("\nErroneous data : %s\n",t);
}
crc();
for(e=0;(e<N-1) && (cs[e]!
='1');e++); if(e<N-1)
printf("\nError
detected\n\n"); else
printf("\nNo error detected\
n\n"); printf("\n \
n");
return 0;
}
Output:
3. Develop a simple data link layer that performs the flow control using the
sliding
window protocol,and loss recovery using the Go-Back-N mechanism.
In computer networks sliding window protocol is a
method to transmit data on a network. Sliding window protocol
is applied on the Data Link Layer of OSI model. At data link
layer data is in the form of frames. In Networking, Window
simply means a buffer which has data frames that needs to be
transmitted.
Both sender and receiver agrees on some window size. If
window size=w then after sending w frames sender waits for
the acknowledgement (ack) of the first frame.
As soon as sender receives the acknowledgement of a frame it
is replaced by the next frames to be transmitted by the sender.
If receiver sends a collective or cumulative acknowledgement
to sender then it understands that more than one frames are
properly received, for eg:- if ack of frame 3 is received it
understands that frame 1 and frame 2 are received properly.
In sliding window protocol the receiver has to have some
memory to compensate any loss in transmission or if the
frames
Efficiencyare received
of Sliding unordered.
Window
Protocol
W = Window Size
tx = Transmission
time tp =
Propagation
delay window works in full duplex
Sliding
mode
2. It i of two types:-
Selective Repeat: Sender transmits only that frame which is
erroneous or is lost.
Go back n: Sender transmits all frames present in the window that
occurs after the error bit including error bit also.
Sliding#include<stdi
Window Protocol Program in C
o.h> int
main()
{
int w,i,f,frames[50];
printf("Enter window
size: ");
scanf("%d",&w);
printf("\nEnter number of frames to
transmit: "); scanf("%d",&f);
printf("\nEnter %d frames:
",f); 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:
Program:
#include<stdio
.h> int main()
{
intwindowsize,sent=0,a
ck,i; printf("enter
window size\n");
scanf("%d",&windowsiz
e); 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;
}

Outpu
t:
4.Implement Dijkstra’s algorithm to compute the shortest path through a network.
The main function of the network layer is routing packets from
the source machine to the destination machine. In most networks,
packets will require multiple hops to make the journey.
The routing algorithm is that part of the network layer
software responsible for deciding which output line an incoming
packet should be transmitted on.
Dijkstra's algorithm is a non-adaptive routing algorithm which is very
widely used
to route packets from source to destination through various routers
available during the transmission. It is implemented at the network
layer of the architecture where data packets are sent through
routers which maintain routing tables that help to denote the exact
location to where the destined packets need to be delivered. Major
advantage in using Dijkstra's algorithm is that it forwards the data
packets from source to destination through the most optimized path
in terms of both the distance and cost observed. It prompts the user
to enter the number of nodes and the source and destination nodes
among them. In addition, the algorithm written below also asks for
the neighbour to each node with the distances to reach to them
from each node is also prompted. All this data is stored and used
further to calculate and estimate the best path possible for data
packets to reach their destination from source. Program below
explains it in a much better way.

#include<stdio.h
> #define
INFINITY 9999
#define MAX 10
void dijkstra(int G[MAX][MAX],int n,int
startnode); int main()
{
int G[MAX]
[MAX],i,j,n,u;
printf("Enter no. of
vertices:");
scanf("%d",&n);
printf("\nEnter the adjacency
matrix:\n"); for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i
][j]); printf("\nEnter the
starting node:");
scanf("%d",&u);
dijkstra(G,n,
u); return
0;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{
int cost[MAX]
[MAX],distance[MAX],pred[MAX]; int
visited[MAX],count,mindistance,nextn
ode,i,j;
//pred[] stores the predecessor of each node
//count gives the number of nodes seen so far
//create the cost
matrix for(i=0;i<n;i+
+)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
//initialize pred[],distance[]
and visited[] for(i=0;i<n;i++)
{
distance[i]=cost[startn
ode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnod
e]=0;
visited[startnode
]=1; count=1;
while(count<n-1)
{
mindistance=INFINITY;
//nextnode gives the node at minimum distance
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance
[i]; nextnode=i;
}
//check if a better path exists
through nextnode
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{

distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}
//print the path and distance of
each node for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);
j=i;
do
{
j=pred[j];
printf("<-
%d",j);
}
while(j!=startnode);
}
}

Output:
5.Take an example subnet of hosts and obtain a broadcast tree for the subnet.

IP addressing is the allocation of unique ID to each and every


system connected in a network to maintain communication among
them throughout the affixed network. There are 5 classes of IP
Addresses namely A through E with the range varying from one
class to the other class. A subnet is a network allocation to similar
systems or same hierarchical systems present in a allocated
network like an organization. Each and every system can be reached
through a client-server computing environment where the server
acts as the Master and the clients acts as the Slaves to form a
Master Slave computing environment. Below programs show the
calculation of network addresses with subnet predefinition and
subnet generation.

Program:
#include<stdio.h>
int p,q,u,v,n;int
min=99,mincost=0; int
t[50][2],i,j;
int
parent[50],edge[50]
[50]; void main()
{
//clrscr();
printf("\n Enter the number of nodes");
scanf("%d",&n); for(i=0;i<n;i++)
{
printf("%c\
t",65+i);
parent[i]=-1;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%c",65+i);
for(j=0;j<n;j++)
scanf("%d",&edge[
i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;
j++)
if(edge[i][j]!
=99)
if(min>edge[i][j])
{
min=edge[
i][j];
u=i;v=j;
}
p=find(
u);
q=find(
v); if(p!
=q)
{
t[i][0]=u; t[i][1]=v;
mincost=mincost+edge[u][v];
sunion(p,q);
}
else
{
t[i][0]=-1;t[i][1]=-1;

}
min=99;
}
printf("Minimum cost is %d\n Minimum spanning tree is\n"
,mincost); for(i=0;i<n;i++)
if(t[i][0]!=-1 && t[i][1]!=-1)
{
printf("%c %c %d", 65+t[i][0], 65+t[i][1],edge[t[i][0]][t[i][1]]);printf("\n");
}
getch();
}
sunion(int l,int m)
{
parent[l]=m;
}
find(int l)
{
if(parent[l]>
0)
l=parent[l];
return l;
}
Output:

6. Implement distance vector routing algorithm for obtaining routing


tables at each node.
The distance vector routing algorithm works by having each
router maintain a routing table, giving the best-known distance from
source to destination and which route is used to get there. These
tables are updated by exchanging the information with the neighbor
having a direct link.
Program:
#include<stdio.h
> struct node
{
unsigned
dist[20];
unsigned
from[20];
}rt[10];
int main()
{
int dmat[20]
[20]; int
n,i,j,k,count=0;
//clrscr();
printf("\nEnter the number of
nodes : "); scanf("%d",&n);
printf("Enter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[
i][j]); dmat[i]
[i]=0;
rt[i].dist[j]=dmat
[i][j];
rt[i].from[j]=j;}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
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<n;i++)
{
printf("\nState value for router %d is \
n",i+1); for(j=0;j<n;j++)
{
printf("\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n");
}

Output:
7.Implement data encryption and data decryption.
Encryption is the process by which a readable message is
converted to an unreadable form to prevent unauthorized parties
from reading it. Decryption is the process of converting an
encrypted message back to its original (readable) format. The
original message is called the plaintext message.
Program:
#include
<stdio.h>
#include
<string.h> int
main()
{
int i, x;
char str[100];
//clrscr();
printf("\nPlease enter a
string:\t"); gets(str);
printf("\nPlease choose following
options:\n"); printf("1 = Encrypt the
string.\n");
printf("2 = Decrypt the string.\n");
scanf("%d", &x);
//using switch case
statements switch(x)
{
case 1:
for(i = 0; (i< 100 &&str[i] != '\0'); i++)
str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII
value printf("\nEncrypted string: %s\n", str);
break;
case 2:
for(i = 0; (i< 100 &&str[i] != '\0'); i++)
str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to
ASCII value

printf("\nDecrypted string: %s\n",


str); break;
default:
printf("\nError\
n");
}
//getch();
return 0;
}

Output:
Please enter a string: hello
Please choose following
options:
1 = Encrypt the string.
2 = Decrypt the string.
1
Encrypted string: khoor
Please enter a string:
khoor
Please choose following options:
1 = Encrypt the string.
2 = Decrypt the
string. 2
Decrypted string: hello

RSA method is based on some principles from number theory.


In encryption process divide the plain text into blocks, so that each
plain text message p falls in the interval 0<p<n this can be done by
grouping the plain text into blocks of k bits. Where k is the largest
integer for which 2 power k <n is true. The security of this method
is based on
the difficulty of factoring large numbers. The encryption and
decryption functions are inverses.

/*Using RSA algorithm encrypt a text data and Decrypt the same*/
#include<stdi
o.h>
#include<coni
o.h>
#include<ctyp
e.h>
#include<mat
h.h>
#include<stri
ng.h> void
main()
{
int
a,b,i,j,t,x,n,k=0,flag=0,prime[
100]; char m[20],pp[20];
float
p[20],c[20];
double e, d;
//clrscr();
for(i=0;i<50;i++)
{
flag=0;
for(j=2;j<i/2;j+
+) if(i%j==0)
{
flag=1;break;
}
if(flag==
0)
prime[k+
+]=i;
}
a=prime[k-1];
b=prime[k-2];
n=a*b;t=(a-
1)*(b-1);
e=(double)pri
me[2];
d=1/(float)e;printf("\nKey of encryption
is:%lf\n",d); printf("\nEnter plain the
text:");
scanf("%s", &m);
x=strlen(m);
printf("\nDecryption status From Source to
Destination:\n"); printf("\nSource\t-> <-
destination\n");
printf("\nChar\tnumeric\tcipher\t\tnumeric\t\tchar \n");
printf("\
n***********************************************************\
n"); printf("\n");
for(i=0;i<x;i++)
{
printf("%c",m[i]);
printf("\t%d",m[i]-97);
c[i]=pow(m[i]-97,(float)e);
c[i]=fmod(c[i],(float)n);
printf("\t%f",c[i]);
p[i]=pow(c[i],(float)d); p[i]=fmod(p[i],
(float)n); printf("\t%f",p[i]);
pp[i]=p[i]+97; printf("\t
%c\n",pp[i]);
printf("\n***********************************************************\n");
printf("\n");
}
getch();
}
Output:
Key of encryption
is:0.500000 Enter plain
the text:hello
Decryption status From Source to Destination:
Source ->------------------------------------<-destination
Char numeric cipher numeric char
**********************************************
************* h 7 49.000000
7.000000 h
***********************************************************
e 4 16.000000 4.000000 e
*********************************************
************** l 11 121.000000
11.000000 l
***********************************************************
l 11 121.000000 11.000000 l
**********************************************
************* o 14 196.000000
14.000000 o
***********************************************************

8.write a program for congestion control using Leaky bucket algorithm.


Aim: In the network layer, before the network can make
Quality of service guarantees, it must know what traffic is being
guaranteed. One of the main causes of
congestion is that traffic is often bursty.Traffic Shaping is a
mechanism to control the amount and the rate of the traffic sent to
the network. Approach of congestion management is called Traffic
shaping. Traffic shaping helps to regulate rate of data transmission
and reduces congestion. One kind of traffic shaping algorithm is
Leaky Bucket. Suppose we have a bucket in which we are pouring
water in a random order but we have to get water in a fixed rate, for
this we will make a hole at the bottom of the bucket. It will ensure
that water coming out is in some fixed rate, and also if bucket will
full we will stop pouring in it.The input rate can vary, but the output
rate remains constant. Similarly, in networking, a technique called
leaky bucket can smooth out bursty traffic. Bursty chunks are stored
in the bucket and sent out at an average rate.

Program:
#include<stdi
o.h>
#include<coni
o.h> void
main()
{
int
i,no_of_queries,storage,output_pkt
_size; int
input_pkt_size,bucket_size,size_lef
t;
//clrscr();
storage=0; //initial packets in the bucket
no_of_queries=4; //total no. of times bucket content is checked
//total no. of packets that can
// be accomodated in the
bucket bucket_size=10;
//no. of packets that enters the bucket at a time
input_pkt_size=4;
//no. of packets that exits the
bucket at a time
output_pkt_size=1;
for(i=0;i<no_of_queries;i++)
{
size_left=bucket_size-storage;
//space left
if(input_pkt_size<=(size_left))
{
storage+=input_pkt_size;
printf("Buffer size= %d out of
bucket size=%d\n"
,storage,bucket_size);
}
else
{
printf("Packet loss = %d\n",input_pkt_size-(size_left));
storage=bucket_size; //full size
printf("Buffer size= %d out of
bucket size=%d\n"
,storage,bucket_size);
}
storage-=output_pkt_size;
}
getch();
}
Output:
9.Write a program for frame sorting techniques used in buffers.
A frame is a digital data transmission unit in computer
networking and telecommunication. A frame typically includes frame
synchronization features consisting of a sequence of bits or symbols
that indicate to the receiver the beginning and end of the payload
data within the stream of symbols or bits it receives. If a receiver is
connected to the system in the middle of a frame transmission, it
ignores the data until it detects a new frame synchronization
sequence
Program:
#include<stdio.h>
#include<string.h>
#define
FRAM_TXT_SIZ 3
#define MAX_NOF_FRAM 127
char str[FRAM_TXT_SIZ*MAX_NOF_FRAM];
struct frame // structure maintained to hold frames
{ char
text[FRAM_TXT_SIZ];
int seq_no;
}fr[MAX_NOF_FRAM],
shuf_ary[MAX_NOF_FRAM]; int
assign_seq_no() //function which splits
message
{
int k=0,i,j; //into frames and assigns
sequence no for(i=0; i<strlen(str); k+
+)
{ fr[k].seq_no = k;
for(j=0; j < FRAM_TXT_SIZ
&&str[i]!='\0'; j++) fr[k].text[j] =
str[i++];
}
printf("\nAfter assigning sequence
numbers:\n"); for(i=0; i< k; i++)
printf("%d:%s
",i,fr[i].text); return k;
//k gives no of frames
}
void generate(int *random_ary, const int limit) //generate array of
random nos
{ int r, i=0,
j; while(i<
limit)
{
r = random()
%limit; for(j=0; j <i;
j++) if(random_ary[j]
== r ) break;
if(i==j ) random_ary[i++] = r;
}}
void shuffle( const int no_frames ) // function shuffles the frames
{
int i, k=0,
random_ary[no_frames];
generate(random_ary,
no_frames); for(i=0;
i<no_frames; i++)
shuf_ary[i] =
fr[random_ary[i]]; printf("\
n\nAFTER SHUFFLING:\n");
for(i=0; i<no_frames; i++)
printf("%d:%s ",shuf_ary[i].seq_no,shuf_ary[i].text);
}
void sort(const int no_frames) // sorts the frames
{
int i,j,flag=1;
struct frame
hold;
for(i=0; i< no_frames-1 && flag==1; i++) // search for frames in sequence
{
flag=0;
for(j=0; j < no_frames-1-i; j++) //(based on seq no.) and display
if(shuf_ary[j].seq_no>shuf_ary[j+1].seq_no)
{
hold = shuf_ary[j];
shuf_ary[j] =
shuf_ary[j+1];
shuf_ary[j+1] =
hold; flag=1;
}
}
}
int main()
{
int no_frames,i;
printf("Enter the message:
"); gets(str);
no_frames =
assign_seq_no();
shuffle(no_frames);
sort(no_frames);
printf("\n\nAFTER
SORTING\n");
for(i=0;i<no_frames;i+
+)
printf("%s",shuf_ary[i].te
xt); printf("\n\n");
}
Output:
Enter the message: welcome to
vmtw After assigning sequence
numbers: 0:wel 1:com 2:e t 3:o v
4:mtw
AFTER SHUFFLING:
3:o v 1:com 2:e t 0:wel 4:mtw
AFTER SORTING
welcome to vmtw
10. Wireshark
i. Packet Capture Using Wire shark
ii.Starting Wire shark
iii.Viewing Captured Traffic
iv.Analysis and Statistics & Filters.
Wireshark is an open-source packet analyzer, which is used for
education, analysis, software development, communication protocol
development, and network troubleshooting.
It is used to track the packets so that each one is filtered to
meet our specific needs. It is commonly called as a sniffer, network
protocol analyzer, and network analyzer. It is also used by network
security engineers to examine security problems.
Wireshark is a free to use application which is used to
apprehend the data back and forth. It is often called as a free
packet sniffer computer application. It puts the network card into an
unselective mode, i.e., to accept all the packets which it receives.

Uses of Wireshark:
Wireshark can be used in the following ways:
1. It is used by network security engineers to examine security problems.
2. It allows the users to watch all the traffic being passed over the
network.
3. It is used by network engineers to troubleshoot network issues.
4. It also helps to troubleshoot latency issues and malicious
activities on your network.
5. It can also analyze dropped packets.
6. It helps us to know how all the devices like laptop, mobile
phones, desktop, switch, routers, etc., communicate in a local
network or the rest of the world.
What is a packet?
A packet is a unit of data which is transmitted over a network
between the origin and the destination. Network packets are small,
i.e., maximum 1.5 Kilobytes for Ethernet packets and 64 Kilobytes
for IP packets. The data packets in the Wireshark can be viewed
online and can be analyzed offline.

Installation of Wireshark Software


Below are the steps to install the Wireshark software on the computer:
• Open the web browser.
• Search for 'Download Wireshark.'
• Select the Windows installer according to your system
configuration, either 32-bt or 64-bit. Save the program and
close the browser.
• Now, open the software, and follow the install instruction
by accepting the license.
• The Wireshark is ready for use.

i. Packet Capture Using Wire shark


Capturing your traffic with
Wireshark After starting
Wireshark, do the following:
1. Select Capture | Interfaces
2. Select the interface on which packets need to be captured.
This will usually be the interface where the Packet/s column is
constantly changing, which would indicate the presence of live
traffic). If you have multiple network interface cards (i.e. LAN
card and Wi-Fi adapter) you may need to check with your IT
administrator to determine the right interface.
3. Click the Start button to start the capture.
4. Recreate the problem. The capture dialog should show the
number of packets increasing. Try to avoid running any other
internet applications while capturing, closing other browsers,
Instant messengers etc.
5. Once the problem which is to be analyzed has been
reproduced, click on Stop. It may take a few seconds for
Wireshark to display the packets captured.
6. Save the packet trace in the default format. Click on the File
menu option and select Save As. By default Wireshark will save
the packet trace in libpcap format. This is a filename with
a.pcap extension.

ii.Starting Wire
shark. Start
Wireshark
Two different methods for starting Wireshark are available.
These include the Start menu and the Run command box.
Method 1 - Start Menu
To start Wireshark using the Start menu:
1. Open the Start menu.
2. Select All Programs.
3. Select Wireshark.
Method 2 - Run Command
To start Wireshark using the Run command box:
1. Open the Start menu or press the Windows key + R.
2. Type Wireshark in the Run command box.
3. Press Enter.

iii.Viewing Captured Traffic


Viewing Packets You Have
Captured
Once you have captured some packets or you have opened a
previously saved capture file, you can view the packets that are
displayed in the packet list pane by simply clicking on a packet in
the packet list pane, which will bring up the selected packet in the
tree view and byte view panes.
You can then expand any part of the tree to view detailed information
about each
protocol in each packet. Clicking on an item in the tree will highlight
the corresponding bytes in the byte view. An example with a TCP
packet selected is shown in Figure, “Wireshark with a TCP packet
selected for viewing”. It also has the Acknowledgment number in
the TCP header selected, which shows up in the byte view as the
selected bytes.
Figure 6.1. Wireshark with a TCP packet selected for viewing
You can also select and view packets the same way while
Wireshark is capturing if you selected “Update list of packets
in real time” in the “Capture Preferences” dialog box.
In addition you can view individual packets in a separate window as
shown in Figure , “Viewing a packet in a separate window”. You can
do this by double-clicking on an item in the packet list or by
selecting the packet in which you are interested in the packet list
pane and selecting View → Show Packet in New Window. This allows
you to easily compare two or more packets, even across multiple
files.
Figure . Viewing a packet in a separate window
Along with double-clicking the packet list and using the main menu
there are a number of other ways to open a new packet window:
• Hold down the shift key and double-click on a frame link in the packet
details.
• From Table 6.2, “The menu items of the “Packet List” pop-up menu”.
• From Table 6.3, “The menu items of the “Packet Details” pop-up menu”.

iv.Analysis and Statistics & Filters.


The “Statistics” Menu
The Wireshark Statistics menu contains the fields shown in Figure. The
“Statistics”
Menu
How to run Nmap scan

How to Run a Simple Nmap Scan


Are you worried about the security of your network or the
security of someone else's? Ensuring that your router is protected
from unwanted intruders is one of the foundations of a secure
network. One of the basic tools for this job is Nmap, or Network
Mapper. This program will scan a target and report which ports are
open and which are closed, among other things. Security specialists
use this program to test the security of a network. To learn how to
use it yourself, see Step 1 below.
Using Zenmap

Download the Nmap installer. This can be found for free from the
developer’s website. It is highly recommended that you download directly
from the developer to avoid any potential viruses or fake files.
Downloading the Nmap installer includes Zenmap, the graphical interface
for Nmap which makes it easy for newcomers to perform scans without
having to learn command lines.
• The Zenmap program is available for Windows, Linux, and Mac
OS X. You can find the installation files for all operating
systems on the Nmap website.

Install Nmap. Run the installer once it is finished downloading. You will be
asked which components you would like to install. In order to get the full
benefit of Nmap, keep all of these checked. Nmap will not install any
adware or spyware.
Run the “Nmap – Zenmap” GUI program. If you left your settings at default
during installation, you should be able to see an icon for it on your
desktop. If not, look in your Start menu. Opening Zenmap will start the
program.

Enter in the target for your scan. The Zenmap program makes scanning a
fairly simple process. The first step to running a scan is choosing your
target. You can enter a domain (example.com), an IP address (127.0.0.1),
a network (192.168.1.0/24), or a combination of those.
• Depending on the intensity and target of your scan, running an
Nmap scan may be against the terms of your internet service
provider, and may land you in hot water. Always check your local
laws and your ISP contract before performing Nmap scans on
targets other than your own network.
2.
Choose your Profile. Profiles are preset groupings of modifiers that change
what is scanned. The profiles allow you to quickly select different types of
scans without having to type in the modifiers on the command line.
Choose the profile that best fits your needs:[1]
• Intense scan - A comprehensive scan. Contains Operating System (OS)
detection, version
detection, script scanning, traceroute, and has aggressive scan
timing. This is considered an intrusive scan.
• Ping scan - This scan simply detects if the targets are online, it does not scan
any ports.
• Quick scan - This is quicker than a regular scan due to
aggressive timing and only scanning select ports.
• Regular scan - This is the standard Nmap scan without any modifiers. It will
return ping
and return open ports on the target.

Click Scan to start scanning. The active results of the scan will be displayed
in the Nmap Output tab. The time the scan takes will depend on the scan
profile you chose, the physical distance to the target, and the target’s
network configuration.
Read your results. Once the scan is finished, you’ll see the message
“Nmap done” at the bottom of the Nmap Output tab. You can now check
your results, depending on the type of scan you performed. All of the
results will be listed in the main Nmap Output tab, but you can use the
other tabs to get a better look at specific data.[2]
• Ports/Hosts - This tab will show the results of your port scan, including the
services for
those ports.
• Topology - This shows the traceroute for the scan you performed.
You can see how many hops your data goes through to reach the
target.
• Host Details - This shows a summary of your target learned through scans,
such as the
number of ports, IP addresses, hostnames, operating systems, and more.
• Scans - This tab stores the commands of your previously-run
scans. This allows you to quickly re-scan with a specific set of
parameters.
Operating System Detection using Nmap

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

Step 2: List of active devices in the


Network nmap -sn
192.168.232.128/24

Let’s do an SYN scan with OS detection in one


of the active IPs Let’s select IP: 192.168.232.2
nmap -sS 192.168.232.2 -O
Running: VMware Player.
OS details: VMware Player virtual NAT device.
Let’s now perform an Aggressive scan To guess the OS
• -sV stands for Service version.
• -A stands for Aggressive.
It will only display the chance of Operation System (OS) on the host
computer with the help of Probability and Percentage.
nmap -sV 192.168.232.2 -A
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.
vi.Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to
Transmission of Packets

What is NS2
NS2 stands for Network Simulator Version 2. It is an open-
source event-driven simulator designed specifically for research in
computer communication networks.
Features of NS2
1. It is a discrete event simulator for networking research.
2. It provides substantial support to simulate bunch of
protocols like TCP, FTP, UDP, https and DSR.
3. It simulates wired and wireless network.
4. It is primarily Unix based.
5. Uses TCL as its scripting language.
6. Otcl: Object oriented support
7. Tclcl: C++ and otcl linkage
8. Discrete event scheduler
Basic Architecture
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. The C++ and the OTcl are linked
together using TclCL

Advantages
1. Cheap- Does not require costly equipment
2. Complex scenarios can be easily tested.
3. Results can be quickly obtained-more ideas can be tested in a smaller
time frame.
4. Supported protocols
5. Supported platforms
6. Modularity
7. Popular
Disadvantages
1. Real system too complex to model. i.e. complicated structure.
2. Bugs are unreliable

You might also like