Computer Networks Lab
B.Tech. III Year I Sem.
Course Objectives:
1. To understand the working principle of various communication protocols.
2. To understand the network simulator environment and visualize a network topology
and observe its performance
3. To analyze the traffic flow and the contents of protocol frames
Course Outcomes:
1. Implement data link layer farming methods
2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools
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.
11. How to run Nmap scan
12. Operating System Detection using Nmap
13. 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
EXPERIMENT NO: 1
Aim: Implement the data link layer framing methods such as.
i. Character stuffing
ii. Bit stuffing.
ALGORITHM:
Step 1. Start
Step 2. Append DLE STX at the beginning of the string
Step 3. Check the data if character is present; if character DLE is present in the string
(example DOODLE) insert another DLE in the string (ex: DOODLEDLE)
Step 4. Transmit DLE ETXat the end of the string
Step 5. Display the string
Step 6. Stop
SOURCE CODE:
i) PROGRAM FOR CHARACTER STUFFING
#include<stdio.h>
#include<string.h>
main()
{
char a[30], fs[50] = " ", t[3], sd, ed, x[3], s[3], d[3], y[3];
inti, j, p = 0, q = 0;
clrscr();
printf("Enter characters to be stuffed:");
scanf("%s", &a);
printf("\nEnter a character that represents starting delimiter:");
scanf(" %c", &sd);
printf("\nEnter a character that represents ending delimiter:");
scanf(" %c", &ed);
x[0] = s[0] = s[1] = sd;
x[1] = s[2] = '\0';
y[0] = d[0] = d[1] = ed;
d[2] = y[1] = '\0';
strcat(fs, x);
for(i = 0; i<strlen(a); i++)
{
t[0] = a[i];
t[1] = '\0';
if(t[0] == sd)
strcat(fs, s);
elseif(t[0] == ed)
strcat(fs, d);
else
strcat(fs, t);
}
strcat(fs, y);
printf("\n After stuffing:%s", fs);
getch();
}
OUTPUT:
Enter characters to be stuffed: goodday
Enter a character that represents starting delimiter: d
Enter a character that represents ending delimiter: g
After stuffing: dggooddddayg
ii) BIT Stuffing program
ALGORITHM
Step 1. Start
Step 2. Initialize the array for transmitted stream with the special bit pattern 0111 1110
which indicates the beginning of the frame.
Step 3. Get the bit stream to be transmitted in to the array.
Step 4. Check for five consecutive ones and if they occur, stuff a bit 0
Step 5. Display the data transmitted as it appears on the data line after appending 0111
1110 at the end
Step 6. For de−stuffing, copy the transmitted data to another array after detecting the
stuffed bits
Step 7. Display the received bit stream
Step 8. Stop
Source code
#include<stdio.h>
#include<conio.h>
void main()
{
inti=0,count=0;
chardatabits[80];
printf("Enter Data Bits: ");
scanf("%s",&databits);
printf("\nData Bits After Bit stuffing: ");
for(i=0; i<strlen(databits); i++)
{
if(databits[i]=='1')
count++;
else
count=0;
printf("%c",databits[i]);
if(count==5)
{
printf("0");
count=0;
}
}
getch();
}
OUTPUT:
EXPERIMENT NO: 2.
AIM: Implement on a data set of characters the three CRC polynomials – CRC 12,
CRC 16 and CRC CCIP.
Theory
CRC means Cyclic Redundancy Check. It is the most famous and traditionally successful
mechanism used in error detection through the parity bits installed within the data and
obtaining checksum which acts as the verifier to check whether the data retreived at the
reciever end is genuine or not. Various operations are involved in implementing CRC on a
data set through CRC generating polynomials. In the program, I have also provided the user
to opt for Error detection whereby he can proceed for it. Understand the program below as it
is much simpler than pretented to be so.
ALGORITHM:
Step 1. A string of n as is appended to the data unit. The length of predetermined divisor
is n+ 1.
Step 2. The newly formed data unit 1. A string of n as is appended to the data unit. The
length of predetermined divisor is n+ 1.
i.e. original data + string of n as are divided by the divisor using binary division and
remainderis obtained. This remainder is called CRC.
Step 3. Now, string of n Os appended to data unit is replaced by the CRC remainder
(which is also of n bit).
Step 4. The data unit + CRC is then transmitted to receiver.
Step 5. The receiver on receiving it divides data unit + CRC by the same divisor &
checks theremainder.
Step 6. If the remainder of division is zero, receiver assumes that there is no error in
data and itaccepts it.
Step 7. If remainder is non-zero then there is an error in data and receiver rejects it.
SOURCE CODE:
#include <stdio.h>
#include <math.h>
main()
{
inti, j, k, m, n, cl;
char a[10], b[100], c[100];
clrscr();
printf("\n ENTER POLYNANOMIAL:");
scanf("%s", &a);
printf("\n ENTER THE FRAME:");
scanf("%s",&b);
m = strlen(a);
n = strlen(b);
for (i = 0; i< m; i++)
/*Toeliminat first zeros inpolynomial */
{
if (a[i] == '1')
{
m = m - i;
break;
}
}
for (k = 0; k < m; k++)
/*To Adjust the polynomial
*/
a[k] = a[k + i];
cl = m + n - 1;
for (i = 0; i< n; i++) /*To copy the original frame to c[]*/
c[i] = b[i];
for (i = n; i< cl; i++) /*To add n-1 zeros at the end of frame */
c[i] = '0';
c[i] = '\0'; /*To make it as a string */
for (i = 0; i< n; i++) /*To set polynomial remainder at end of c[]*/
if (c[i] == '1')
{
for (j = i, k = 0; k < m; k++, j++)
if (a[k] == c[j])
c[j] = '0';
else c[j] = '1';
}
for (i = 0; i< n; i++) /*To copy original data in c[]*/
c[i] = b[i];
printf("\n THE MESSAGE IS: %s", c);
getch();
}
OUTPUT:
ENTER POLYNANOMIAL:1011
ENTER THE FRAME:10011101
THE MESSAGE IS: 10011101011
ENTER POLYNANOMIAL:00101
ENTER THE FRAME:10101011
THE MESSAGE IS: 1010101101
EXPERIMENT NO: 3.
AIM: 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.
ALGORITHM:
Step 1. Start the program.
Step 2. Get the frame size from the user
Step 3. To create the frame based on the user request.
Step 4. To send frames to server from the client side.
Step 5. If your frames reach the server it will send ACK signal to client otherwise it will send
NACK signal to client.
Step 6. Stop the program
SOURCE CODE:
#include<stdio.h>
int main()
{
intw,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:
Enter window size: 3
Enter number of frames to transmit: 5
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
4 6
Acknowledgement of above frames sent is received by sender
EXPERIMENT NO: 4.
AIM: Implement Dijkstra‘s algorithm to compute the Shortest path through a network
ALGORITHM:
Step 1: Create a set shortPath to store vertices that come in the way of the shortest path tree.
Step 2: Initialize all distance values as INFINITE and assign distance values as 0 for source
vertex so that it is picked first.
Step 3: Loop until all vertices of the graph are in the shortPath.
Step 3.1: Take a new vertex that is not visited and is nearest.
Step 3.2: Add this vertex to shortPath.
Step 3.3: For all adjacent vertices of this vertex update distances. Now check every
adjacent vertex of V, if sum of distance of u and weight of edge is elss the update it.
SOURCE CODE:
#include<stdio.h>
#include<conio.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, nextnode, 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[startnode][i];
pred[i] = startnode;
visited[i] = 0;
}
distance[startnode] = 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
EXPERIMENT NO: 5.
AIM: Implement broadcast tree for a given subnet of hosts
ALGORITHM:
Step 1: Start
Step 2: Select any edge of minimal value that is not a loop. This is the first edge of T.
Step 3: Select any remaining edge of G having minimal value that does not from a circuit with
the edges already included in T.
Continue Step 4: until T contains n-1 edges where n is the number of vertices of G.
Step 5: Stop
SOURCE CODE:
#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() {
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");
}
}
sunion(int l, int m) {
parent[l] = m;
}
find(int l) {
if (parent[l] > 0)
l = parent[l];
return l;
}
OUTPUT:
EXPERIMENT NO: 6
NAME OF THE EXPERIMENT: Distance Vector routing.
AIM: Obtain Routing table at each node using distance vector routing algorithm for a
given subnet.
ALGORITHM:
At each node x,
STEP 1:Initialization
for all destinations y in N:
Dx(y) = c(x,y) // If y is not a neighbor then c(x,y) = ∞
for each neighbor w
Dw(y) = ? for all destination y in N.
for each neighbor w
send distance vector Dx = [ Dx(y) : y in N ] to w
STEP 2: loop
wait(until I receive any distance vector from some neighbor w)
for each y in N:
Dx(y) = minv{c(x,v)+Dv(y)}
If Dx(y) is changed for any destination y
Send distance vector Dx = [ Dx(y) : y in N ] to all neighbors
forever
SOURCE CODE:
#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:
Enter the number of nodes :
3
Enter the cost matrix :
0 2 7
2 0 1
7 1 0
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 NO: 7
NAME OF THE EXPERIMENT: RSA.
AIM: Using RSA algorithm encrypt a text data and Decrypt the same.
ALGORITHM
Step 1: Two prime numbers are selected as p and q
Step 2: n = pq which is the modulus of both the keys.
Step 3: Calculate totient = (p-1)(q-1)
Step 4: Choose e such that e > 1 and coprime to totient which means gcd (e,
totient) must be equal to 1, e is the public key
Step 5: Choose d such that it satisfies the equation de = 1 + k (totient), d is the
private key not known to everyone.
Step 6: Cipher text is calculated using the equation c = m^e mod n where m is the
message.
Step 7: With the help of c and d we decrypt message using equation m = c^d mod
n where d is the private key.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long int p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
char msg[100];
int prime(long int);
void ce();
long int cd(long int);
void encrypt();
void decrypt();
void main()
{
clrscr();
printf("\nENTER FIRST PRIME NUMBER\n");
scanf("%d",&p);
flag=prime(p);
if(flag==0)
{
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER ANOTHER PRIME NUMBER\n");
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q)
{
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER MESSAGE\n");
fflush(stdin);
scanf("%s",msg);
for(i=0;msg[i]!=NULL;i++)
m[i]=msg[i];
n=p*q;
t=(p-1)*(q-1);
ce();
printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
}
int prime(long int pr)
{
int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
{
if(pr%i==0)
return 0;
}
return 1;
}
void ce()
{
int k;
k=0;
for(i=2;i<t;i++)
{
if(t%i==0)
continue;
flag=prime(i);
if(flag==1&&i!=p&&i!=q)
{
e[k]=i;
flag=cd(e[k]);
if(flag>0)
{
d[k]=flag;
k++;
}
if(k==99)
break;
}
}
}
long int cd(long int x)
{
long int k=1;
while(1)
{
k=k+t;
if(k%x==0)
return(k/x);
}
}
void encrypt()
{
long int pt,ct,key=e[0],k,len;
i=0;
len=strlen(msg);
while(i!=len)
{
pt=m[i];
pt=pt-96;
k=1;
for(j=0;j<key;j++)
{
k=k*pt;
k=k%n;
}
temp[i]=k;
ct=k+96;
en[i]=ct;
i++;
}
en[i]=-1;
printf("\nTHE ENCRYPTED MESSAGE IS\n");
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]);
}
void decrypt()
{
long int pt,ct,key=d[0],k;
i=0;
while(en[i]!=-1)
{
ct=temp[i];
k=1;
for(j=0;j<key;j++)
{
k=k*ct;
k=k%n;
}
pt=k+96;
m[i]=pt;
i++;
}
m[i]=-1;
printf("\nTHE DECRYPTED MESSAGE IS\n");
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]);
}
OUTPUT:
EXPERIMENT NO: 8
AIM: Write a program for congestion control using Leaky bucket algorithm.
ALGORITHM:
Step 1: Initialize a counter to n at the tick of the clock.
Step 2: Repeat until n is smaller than the packet size of the packet at the head of the
queue.
1. Pop a packet out of the head of the queue, say P.
2. Send the packet P, into the network
3. Decrement the counter by the size of packet P.
Step 3: Reset the counter and go to step 1.
SOURCE CODE:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main() {
int
packets[8], i, j, clk, b_size, o_rate, i_rate, p_sz_rm = 0, p_sz, p_time;
clrscr();
for (i = 0; i< 5; ++i) {
packets[i] = rand() % 10;
if (packets[i] == 0) --i;
}
printf("Enter output rate:");
scanf("%d", &o_rate);
printf("\nEnter bucket size:");
scanf("%d", &b_size);
for (i = 0; i< 5; ++i) {
if ((packets[i] + p_sz_rm) >b_size) {
if (packets[i] >b_size)
printf("\nIncoming packet size:%d greater than
bucket capacity\ n ",packets[i]);
elseprintf("Bucket size exceeded\n");
}
else {
p_sz = packets[i];
p_sz_rm += p_sz;
printf("\n------------------------------------------------- -
\n ");
printf("Incoming packet:%d", p_sz); printf("\nTransmission left:%d\n", p_sz_rm); p_time =
rand() % 10; printf("Next packet will come at %d", p_time);
for (clk = 0; clk<p_time&&p_sz_rm> 0; ++clk) {
printf("\nTime left %d---No packets to
transmit!!\n ",p_time-clk);
sleep(1);
if (p_sz_rm) {
printf("Transmitted\n");
if (p_sz_rm<o_rate)
p_sz_rm = 0;
elsep_sz_rm -= o_rate;
printf("Bytes remaining:%d\n", p_sz_rm);
} else printf("No packets to transmit\n");
}
}
}
getch();
}
OUTPUT
EXPERIMENT NO: 9
AIM: Write a program for frame sorting techniques used in buffers.
ALGORITHM:
Step 1: Enter the number of frames
Step 2: Enter the frame contents for sequence number
Step 3: divides the stream of bits received from the network layer into manageable data units
called frames
Step 4: If frames are to be distributed to different systems on the network, the Data link layer
adds a header to the frame to define the sender and/or receiver of the frame.
SOURCE CODE:
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define FSize 3
typedef struct packet{int SeqNum; char Data[FSize+1];}packet;
struct packet *readdata, *transdata;
int divide(char *msg) {
int msglen, NoOfPacket, i, j;
msglen = strlen(msg);
NoOfPacket = msglen/FSize;
if ((msglen%FSize)!=0) NoOfPacket++;
readdata = (struct packet *)malloc(sizeof(packet) * NoOfPacket);
for(i = 0; i < NoOfPacket; i++) {
readdata[i].SeqNum = i + 1;
for (j = 0; (j < FSize) && (*msg != '\0'); j++, msg++)
readdata[i].Data[j] = *msg;
readdata[i].Data[j] = '\0';
}
printf("\nThe Message has been divided as follows\n");
printf("\nPacket No. Data\n\n");
for (i = 0; i < NoOfPacket; i++)
printf(" %2d %s\n", readdata[i].SeqNum,
readdata[i].Data);
return NoOfPacket;
}
void shuffle(int NoOfPacket) {
int *Status;
int i, j, trans;
randomize();
Status=(int * )calloc(NoOfPacket, sizeof(int));
transdata = (struct packet *)malloc(sizeof(packet) * NoOfPacket);
for (i = 0; i < NoOfPacket;) {
trans = rand()%NoOfPacket;
if (Status[trans]!=1) {
transdata[i].SeqNum = readdata[trans].SeqNum;
strcpy(transdata[i].Data, readdata[trans].Data);
i++; Status[trans] = 1;
}
}
free(Status);
}
void sortframes(int NoOfPacket) {
packet temp;
int i, j;
for (i = 0; i < NoOfPacket; i++)
for (j = 0; j < NoOfPacket – i-1; j++)
if (transdata[j].SeqNum > transdata[j + 1].SeqNum) {
temp.SeqNum = transdata[j].SeqNum;
strcpy(temp.Data, transdata[j].Data);
transdata[j].SeqNum = transdata[j + 1].SeqNum;
strcpy(transdata[j].Data, transdata[j + 1].Data);
transdata[j + 1].SeqNum = temp.SeqNum;
strcpy(transdata[j + 1].Data, temp.Data);
}
}
void receive(int NoOfPacket) {
int i;
printf("\nPackets received in the following order\n");
for (i = 0; i < NoOfPacket; i++) printf("%4d", transdata[i].SeqNum);
sortframes(NoOfPacket);
printf("\n\nPackets in order after sorting..\n");
for (i = 0; i < NoOfPacket; i++) printf("%4d", transdata[i].SeqNum);
printf("\n\nMessage received is :\n");
for (i = 0; i < NoOfPacket; i++) printf("%s", transdata[i].Data);
}
void main() {
char *msg;
int NoOfPacket;
clrscr();
printf("\nEnter The message to be Transmitted :\n");
scanf("%[^\n]", msg);
NoOfPacket = divide(msg);
shuffle(NoOfPacket);
receive(NoOfPacket);
free(readdata);
free(transdata);
getch();
}
OUTPUT
Enter The messgae to be Transmitted :
hi, it was nice meeting u on sunday
The Message has been divided as follows
Packet No. Data
1 hi,
2 it
3 wa
4 s n
5 ice
6 me
7 eti
8 ng
9 u o
10 n s
11 und
12 ay
Packets received in the following order
4 2 6 3 5 1 8 9 11 7 12 10
Packets in order after sorting..
1 2 3 4 5 6 7 8 9 10 11 12
Message received is :
hi, it was nice meeting u on sunday
EXPERIMENT NO: 10
Note: Find the steps given in experiments to run the tools.
AIM: Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
Wireshark
What is Wireshark?
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.
i) Starting Wire shark
Step 1: Open the wire shark software
ii) Packet Capture Using Wire shark
Step 1:
.
Step 2:
Step 3:
Step 4: Create a file to save captured packets
Step 5: Press red button to stop capturing packets
Step 6: Now open the captured packet file
iii) Viewing Captured Traffic
Step 1: 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 1, “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.
Fig 1. Wireshark with a TCP packet selected for viewing
Step 2:
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 2,
“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
Step 3: View → Show Packet in New Window. This allows you to easily compare two or
more packets, even across multiple files.
Figure 2. Viewing a packet in a separate window
iv) Analysis and Statistics & Filters.
Analyzing data packets on Wireshark
Wireshark shows you three different panes for inspecting packet data. The Packet List, the
top pane, lists all the packets in the capture. When you click on a packet, the other two panes
change to show you the details about the selected packet. You can also tell if the packet is
part of a conversation. Here are details about each column in the top pane:
No.: This is the number order of the packet captured. The bracket indicates that this
packet is part of a conversation.
Time: This column shows how long after you started the capture this particular packet
was captured. You can change this value in the Settings menu to display a different
option.
Source: This is the address of the system that sent the packet.
Destination: This is the address of the packet destination.
Protocol: This is the type of packet. For example: TCP, DNS, DHCPv6, or ARP.
Length: This column shows you the packet’s length, measured in bytes.
Info: This column shows you more information about the packet contents, which will
vary depending on the type of packet.
Packet Details, the middle pane, shows you as much readable information about the packet
as possible, depending on the packet type. You can right-click and create filters based on the
highlighted text in this field.
The bottom pane, Packet Bytes, displays the packet exactly as it was captured in
hexadecimal.
When looking at a packet that is part of a conversation, you can right-click the packet and
select Follow to see only the packets that are part of that conversation.
Wireshark filters
Some of the best features of Wireshark are the capture filters and display filters. Filters allow
you to view the capture the way you need to see it to troubleshoot the issues at hand. Below
are several filters to get you started.
Wireshark capture filters
Capture filters limit the captured packets by the chosen filter. If the packets don’t match the
filter, Wireshark won’t save them. Examples of capture filters include:
host IP-address: This filter limits the captured traffic to and from the IP address
net 192.168.0.0/24: This filter captures all traffic on the subnet
dst host IP-address: Capture packets sent to the specified host
port 53: Capture traffic on port 53 only
port not 53 and not arp: Capture all traffic except DNS and ARP traffic
Wireshark display filters
Wireshark display filters change the view of the capture during analysis. After you’ve
stopped the packet capture, use display filters to narrow down the packets in the Packet List
to troubleshoot your issue.
One of the most useful display filters is:
ip.src==IP-address and ip.dst==IP-address
This filter shows packets sent from one computer (ip.src) to another (ip.dst). You can also
use ip.addr to show packets to and from that IP. Other filters include:
tcp.porteq 25: This filter will show you all traffic on port 25, which is usually SMTP traffic
icmp: This filter will show you only ICMP traffic in the capture, most likely they are pings
ip.addr != IP_address: This filter shows you all traffic except the traffic to or from the
specified computer
Analysts even build filters to detect specific attacks, like this filter used to detect the Sasser
worm:
ls_ads.opnum==0x09
Step 4: Metrics and statistics
Under the Statistics menu, you’ll find a plethora of options to view details about your capture.
Step 5: Capture File Properties:
Step 6: Wireshark I/O Graph:
EXPERIMENT NO: 11
AIM: How to run Nmap scan
1. 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.
2. 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.
Step 1:
3. 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.
Step 2:
4. 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.
Step 3:
5. 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
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.
Step 4:
6. 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.
Step 5:
7. 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.
EXPERIMENT NO: 12
AIM: Operating System Detection using Nmap
Step 1: Step 2:
Step 3:
EXPERIMENT NO: 13
AIM: Do the following using NS2 Simulator
NS2 Simulator-Introduction.
1. 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.
2. 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
3. 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
Basic Architecture of Network simulator 2
Simulate to Find the Number of Packets Dropped
//creating an agent object
set ping0 [new Agent/Ping]
//agent object node0
$ns attach-agent $n0 $ping0
set ping1 [new Agent/Ping]
//agent object node1
$ns attach-agent $n1 $ping1
set ping4 [new Agent/Ping]
//agent object node4
$ns attach-agent $n4 $ping4
set ping5 [new Agent/Ping]
//agent object node5
$ns attach-agent $n5 $ping5
//node2 and node3 acts as an intermediate nodes
//$ns connect $source $destination
$ns connect $ping0 $ping4
$ns connect $ping1 $ping5
//function to constantly ping th destination at an interval of 0.01s
proc sendPingPacket {} {
//global objects
global ns ping0 ping1
//time interval
set time 0.01
//sets now with the current time of simulation
set now [$ns now]
//when the current simulation time($now) + time($time = 0.01) occurs a ping is sent to
the destination
$ns at [expr $now + $time] "$ping0 send"
$ns at [expr $now + $time] "$ping1 send"
//pingPacket is sent
$ns at [expr $now + $time] "sendPingPacket"
}
//In the Tcl code, a procedure 'Agent/Ping recv {from rtt}' has to be defined which
allows the user to react to the ping result.
Agent/Ping instproc recv {from rtt} {
global seq
$self instvar node_
}
$ns at 0.01 "sendPingPacket"
$ns at 10.0 "finish"
0 Comments
IF U HAVE ANY DOUBTS PLEASE COMMENT