III-I CN r20 Lab Manual (Final)
III-I CN r20 Lab Manual (Final)
for
computer network
1
COMPUTER NETWORKS LAB
Course Objectives:
Learn basic concepts of computer networking and acquire practical notions of protocols with
the emphasis on TCP/IP. A lab provides a practical approach to Ethernet/Internet networking:
networks are assembled, and experiments are made to understand the layered architecture and
how do some important protocols work
Course Outcomes:
By the end of the course student will be able to
Know how reliable data communication is achieved through data link layer.
Suggest appropriate routing algorithm for the network.
Provide internet connection to the system and its installation.
Work on various network management tools
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, CRC16 and CRC CCIP.
6. Write a Program to implement Sliding window protocol for Go back N.
7. Write a Program to implement Sliding window protocol for Selective repeat.
8. Write a Program to implement Stop and Wait Protocol.
9. Write a program for congestion control using leaky bucket algorithm
10. Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path through a
graph.
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).
12. Write a Program to implement Broadcast tree by taking subnet of hosts.
13. Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
14. How to run Nmap scan
15. Operating System Detection using Nmap
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.EXPERIMENT1:
2
1. Study of Network devices in detail and connect the computers in Local Area Network
Hub:
Advantages:
3.It is a cheap.
Disadvantages:
Repeater
3
Repeaters:
Advantages of Repeaters:
Repeaters are simple to install and can easily extend the length or the coverage area of
networks.
They are cost effective.
Repeaters don’t require any processing overhead. The only time they need to be investigated
is in case of degradation of performance.
They can connect signals using different types of cables.
Disadvantages of Repeaters:
Advantages:
1.Increase capacity.
Disadvantages:
1.Limited broadcast.
4
Bridge:
Advantages:
Disadvantages:
Router:
Advantages:
5
Disadvantages:
1.Less bandwith.
Gateway:
Advantages:
Disadvantages:
1.Time delay.
2.Connection fail.
3.Trouble Shooting.
Modem:
6
Advantages:
1.Connecting Lan.
3.Data Communication.
Disadvantages:
Repeaters:
Advantages of Repeaters:
Repeaters are simple to install and can easily extend the length or the coverage area of
networks.
They are cost effective.
Repeaters don’t require any processing overhead. The only time they need to be investigated
is in case of degradation of performance.
They can connect signals using different types of cables.
Disadvantages of Repeaters:
On the host computer, follow these steps to share the Internet connection:
8. Under Internet Connection Sharing, select the Allow other network users to
connect through this computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a dial-up
connection whenever a computer on my network attempts to access the Internet
7
check box if you want to permit your computer to automatically connect to the Internet.
When Internet Connection Sharing is enabled, your LAN adapter will be set to use IP
address 192.168.0.1. Your computer may lose connectivity with other computers on
your network. If these other computers have static IP addresses, it is a good idea to set
them to obtain their IP addresses automatically. Are you sure you want to enable
Internet Connection Sharing?
The network adapter that is connected to the LAN is configured with a static IP address
of 192.168.0.1 and a subnet mask of 255.255.255.0
To connect to the Internet by using the shared connection, you must confirm the LAN
adapter IP configuration, and then configure the client computer. To confirm the LAN
adapter IP configuration, follow these steps:
Experiment2: Write a Program to implement the data link layer farming methods such as
AIM: Implement the data link layer framing methods such as character stuffing.
Source Code:
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
int j,l,m,c,k;
char a[50],b[50];
8
scanf("%s",a);
strcpy(b,"DLESTX");
m=strlen(a);
for(j=0;j<m;)
if(a[j]=='d')
if(a[j+1]=='l')
if(a[j+2]=='e')
c=j+2;
for(l=0;l<3;l++)
for(k=m;k>c;k--)
a[k]=a[k-1];
m++;
a[m]='\0';
c+=1;
a[j+3]='d';
a[j+4]='l';
a[j+5]='e';
a[m]='\0';
j+=5;
9
}
j++;
strcat(b,a);
strcat(b,"DLEETX");
printf("\n%s",b);
printf("\nReceiver side:");
m=strlen(a);
for(j=0;j<m;)
if(a[j]=='d')
if(a[j+1]=='l')
if(a[j+2]=='e')
c=j;
for(l=0;l<3;l++)
for(k=c;k<m;k++)
a[k]=a[k+1];
c++;
j=c;
10
}
j++;
printf("\n%s",a);
getch();
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
int n,i,j;
clrscr();
scanf("%s",a);
scanf("%d",&j);
if(j>strlen(a))
else{
strncat(b,a,j);
11
strcat(b,c);
for(i=j;i<strlen(a);i++)
b[i+4]=a[i];
strcpy(c,"DLESTX");
strcat(c,b);
strcat(c,"DLEETXA");
printf("%s\n",c);
getch();
BITSTUFFING
#include<stdio.h>
int main()
int i=0,count=0;
char databits[80];
scanf("%s",databits);
12
printf("Data Bits Before Bit Stuffing:%s",databits);
if(databits[i]=='1')
count++;
else
count=0;
printf("%c",databits[i]);
if(count==5)
printf("0");
count=0;
return 0;
#include<stdio.h>
#include<conio.h>
int com(int);
void main()
13
{
scanf("%d", &dl);
scanf("%d", &data1[i]);
scanf("%d", &data2[i]);
printf("%d", data1[i]);
printf("%d", data2[i]);
printf("%d", newdata[i]);
14
}
checksum[i] = com(newdata[i]);
printf("%d", checksum[i]);
printf("%d", data1[i]);
printf(" ");
printf("%d", data2[i]);
printf(" ");
printf("%d", checksum[i]);
printf("%d", newdata[i]);
15
}
comp[i] = com(newdata[i]);
printf("%d", comp[i]);
carry = 1;
return 0;
carry = 1;
return 1;
carry = 0;
return 1;
16
else if (x == 1 && y == 0 && carry == 1)
carry = 1;
return 0;
carry = 0;
return 1;
carry = 1;
return 0;
carry = 0;
return 0;
else
carry = 0;
return 1;
int com(int a)
17
{
if (a == 0)
return 1;
else
return 0;
EXPERIMENT4: Write a program for Hamming Code generation for error detection and correction.
HAMMING CODE
#include<stdio.h>
#include<conio.h>
void main() {
int data[10];
int dataatrec[10],r,r2,r1,r4,i;
scanf("%d",&data[7]);
scanf("%d",&data[6]);
scanf("%d",&data[5]);
18
scanf("%d",&data[3]);
data[1]=data[3]^data[5]^data[7];
data[2]=data[3]^data[6]^data[7];
data[4]=data[5]^data[6]^data[7];
for(i=7;i>0;i--)
printf("%d",data[i]);
for(i=7;i>0;i--)
scanf("%d",&dataatrec[i]);
r1=dataatrec[1]^dataatrec[3]^dataatrec[5]^dataatrec[7];
r2=dataatrec[2]^dataatrec[3]^dataatrec[6]^dataatrec[7];
r4=dataatrec[4]^dataatrec[5]^dataatrec[6]^dataatrec[7];
r=r4*4+r2*2+r1 ;
if(r==0) {
else {
for(i=7;i>0;i--)
printf("%d",data[i]);
19
printf("\nData received : ");
for(i=7;i>0;i--)
printf("%d",dataatrec[i]);
if(dataatrec[r]==0)
dataatrec[r]=1;
else
dataatrec[r]=0;
for (i=7;i>0;i--) {
printf("%d",dataatrec[i]);
20
Experiment5:Write a Program to implement on a data set of characters the three CRC
polynomials – CRC 12, CRC16 and CRC CCIP.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
int i,j,keylen,msglen;
clrscr();
gets(input);
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for(i=0;i<keylen-1;i++)
input[msglen+i]='0';
for(i=0;i<keylen;i++)
temp[i]=input[i];
for(i=0;i<msglen;i++)
quot[i]=temp[0];
if(quot[i]=='0')
for(j=0;j<keylen;j++)
21
key[j]='0';
else
for(j=0;j<keylen;j++)
key[j]=key1[j];
for(j=keylen-1;j>0;j--)
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
strcpy(rem,temp);
printf("\nQuotient is ");
for(i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
for(i=0;i<msglen;i++)
printf("%c",input[i]);
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
getch();
22
OUTPUT:
Quotient is 10010010000
Remainder is 00000
#include<stdio.h>
int main()
int windowsize,sent=0,ack,i;
scanf("%d",&windowsize);
while(1)
for(i=0;i<windowsize;i++)
sent++;
if(sent==windowsize)
break;
scanf("%d",&ack);
if(ack==windowsize)
break;
else
23
sent=ack;
return 0;
output
Experiment7:. Write a Program to implement Sliding window protocol for Selective repeat.
#include<stdio.h>
int main()
int windowsize,sent=0,ack,i;
scanf("%d",&windowsize);
while(1)
sent++;
if(sent == windowsize)
break;
scanf("%d",&ack);
24
break;
return 0;
output
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define TIMEOUT 5
#define MAX_SEQ 1
#define TOT_PACKETS 8
typedef struct
int data;
}packet;
typedef struct
25
int kind;
int seq;
int ack;
packet info;
int err;
}frame;
frame DATA;
void reciever();
void sender();
int DISCONNECT=0;
/*__________________________________________________________________________*/
void main()
clrscr();
randomize();
while(!DISCONNECT)
26
sender();
delay(400);
reciever();
getch();
/*__________________________________________________________________________*/
void sender()
static frame s;
packet buffer;
event_type event;
if(flag==0)
from_network_layer(&buffer);
s.info = buffer;
s.seq = frame_to_send;
turn = 'r';
to_physical_layer(&s);
flag = 1;
wait_for_event_sender(&event);
if(turn=='s')
27
if(event==frame_arrival)
from_network_layer(&buffer);
inc(frame_to_send);
s.info = buffer;
s.seq = frame_to_send;
turn = 'r';
to_physical_layer(&s);
if(event==timeout)
turn = 'r';
to_physical_layer(&s);
/*__________________________________________________________________________*/
void reciever()
frame r,s;
event_type event;
wait_for_event_reciever(&event);
if(turn=='r')
28
if(event==frame_arrival)
from_physical_layer(&r);
if(r.seq==frame_expected)
to_network_layer(&r.info);
inc(frame_expected);
else
turn = 's';
to_physical_layer(&s);
if(event==err)
/*__________________________________________________________________________*/
(*buffer).data = i;
i++;
/*___________________________________________________________________________*/
29
void to_physical_layer(frame *s)
{ // 0 means error
/*___________________________________________________________________________*/
DISCONNECT = 1;
printf("\nDISCONNECTED");
/*___________________________________________________________________________*/
*buffer = DATA;
/*___________________________________________________________________________*/
void wait_for_event_sender(event_type * e)
if(turn=='s')
timer++;
30
if(timer==TIMEOUT)
*e = timeout;
timer = 0;
return;
if(DATA.err==0)
*e = err;
else
timer = 0;
*e = frame_arrival;
/*____________________________________________________________________________*/
void wait_for_event_reciever(event_type * e)
if(turn=='r')
if(DATA.err==0)
*e = err;
else
*e = frame_arrival;
31
output
Experiment9: Write a program for congestion control using leaky bucket algorithm
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
if(a>bucketSize)
printf("\n\t\tBucket overflow");
else {
delay(500);
while(a>b){
a-=b;
delay(500);
32
printf("\n\t\tBucket output successful");
void main() {
randomize();
scanf("%d",&op);
for( i=1;i<=5;i++){
delay(random(100));
pktSize=random(100);
bktInput(pktSize,op);
output
#include <stdio.h>
#include <conio.h>
33
#define infinity 999
int i,u,count,w,flag[10],min;
for(i=1;i<=n;i++)
flag[i]=0,dist[i]=cost[v][i];
count=2;
while(count<=n)
min=99;
for(w=1;w<=n;w++)
min=dist[w],u=w;
flag[u]=1;
count++;
for(w=1;w<=n;w++)
dist[w]=dist[u]+cost[u][w];
void main()
int n,v,i,j,cost[10][10],dist[10];
clrscr();
scanf("%d",&n);
34
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=infinity;
scanf("%d",&v);
dij(n,v,cost,dist);
for(i=1;i<=n;i++)
if(i!=v)
printf("%d->%d,cost=%d\n",v,i,dist[i]);
getch();
output
#include<stdio.h>
struct node
35
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
int costmat[20][20];
int nodes,i,j,k,count=0;
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
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
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
36
if(rt[i].dist[j]>costmat[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<nodes;i++)
for(j=0;j<nodes;j++)
printf("\n\n");
getch();
return;
output
37
Experiment12: Write a Program to implement Broadcast tree by taking subnet of hosts.
#include<stdio.h>
#include<conio.h>
void main()
int i;
clrscr();
scanf("%u%*c%u%*c%u%*c%u%*c",&compad[3],&compad[2],&compad[1],&compad[0]);
scanf("%u%*c%u%*c%u%*c%u%*c",&mask[3],&mask[2],&mask[1],&mask[0]);
for(i=0;i<4;i++)
netadr[i]= compad[i]&mask[i];
printf("%u.%u.%u.%u",netadr[3],netadr[2],netadr[1],netadr[0]);
printf("%u.%u.%u.%u",mask[3],mask[2],mask[1],mask[0]);
printf("%u.%u.%u.%u",compad[3],compad[2],compad[1],compad[0]);
getch();
Output
38
13. Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
Wireshark is a network protocol analyzer, or an application that captures packets from
a network connection,
How does Wireshark work? Wireshark is a packet sniffer and analysis tool. It captures
network traffic from ethernet, Bluetooth, wireless (IEEE. 802.11), token ring, and frame
relay connections, among others, and stores that data for offlin
Wireshark is an open source software project, and is released under the GNU
General Public License (GPL
39
40
i.packet capture using wire shark
41
What is packet capture used for?
Packet capturing helps to analyze networks, manage network traffic,
and identify network performance issues. It allows IT teams to detect
intrusion attempts, security issues, network misuse, packet loss, and
network congestion. It enables network managers to capture data packets
directly from the computer network
42
43
ii)Starting wire shark
44
iii) viewing captured trafic
45
Figure 6.1. Wireshark with a TCP packet selected for
viewing
46
iv)analysis and statistics & filters
When exploring data it can be useful to analyse a subset of the cases from the
dataset, for example to see summary statistics for just Male or Female subjects.
To allow analysis of just a subset of cases Analyse-it only analyses the cases
that are visible on the worksheet. Observations on hidden rows will not be
included in the analysis. Rows can be manually hidden to exclude them from
analysis, or Excel's AutoFilter or Advanced Filter can be used to hide rows based
on conditions:
A specific value or category, e.g. filter by Sex to just show Female cases.
A range of the highest or lowest values of the variable. The number of values to
show, e.g. 10, or a percentage of the total number of values, e.g. show 10% of
the top values, can be chosen.
47
A boolean condition using operators such as <, >, <=, >= and using boolean
AND or OR to combine up to two conditions.
IMPORTANT When Analyse-it updates a report it will analyse the cases that are
currently visible in the dataset, rather than the cases that were visible when the
analysis was first performed.
3. Excel shows drop-down arrows alongside the names of the variables of the
dataset. Click the drop-down arrow then click the value to filter to, Top 10... to
filter to a range of values, or Custom... to use a boolean condition.
48
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.
49
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.
50
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
51
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:[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.
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.
52
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.
53
1. Install Nmap. Before using Nmap, you will need to install it so
that you can run it from the command line of your operating
system. Nmap is small and available for free from the developer.
Follow the instructions below for your operating system:
Linux - Download and install Nmap from your repository.
Nmap is available through most of the major Linux
repositories. Enter in the command below based on your
distribution:
Red Hat, Fedora, SUSE
rpm -vhU http://nmap.org/dist/nmap-6.40-
1.i386.rpm (32-bit) OR
rpm -vhU http://nmap.org/dist/nmap-6.40-
1.x86_64.rpm (64-bit)
Debian, Ubuntu
sudo apt-get install nmap
Windows - 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.
Using the installer allows you to quickly install the
command line Nmap tools without having to worry about
extracting to the right folder.
54
If you don’t want the Zenmap graphical user
interface, you can uncheck it during the installation
process.
Mac OS X – Download the Nmap disk image. 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. Use
the included installer to install Nmap on your system.
Nmap requires OS X 10.6 or later.
2.
2
Open your command line. Nmap commands are run from the
command line, and the results are displayed beneath the command. You
can use variables to modify the scan. You can run the scan from any
directory on the command line.
Linux - Open the terminal if you are using a GUI for your
Linux distribution. The location of the terminal varies by
distribution
55
Windows - This can be accessed by pressing the
Windows key + R and then typing “cmd” into the Run
field. Windows 8 users can press Windows key + X and
select Command Prompt from the menu. You can run an
Nmap scan from any directory.
Mac OS X - Open the Terminal application located in the
Utility subfolder of your Applications folder.
3
Run a scan of you target’s ports. To start a basic scan, type nmap
<target>. This will ping the target and scan the ports. This is an easily-
detected scan. The results will be displayed on your screen. You may need
to scroll back up to see all of the results.
4
Run a modified scan. You can use command line variables to change
the parameters of the scan, resulting in more detailed or less detailed
results. Changing the scan variables will change the intrusiveness of the
scan. You can add multiple variables by placing a space between each
one. Variables come before the target: nmap <variable> <variable>
<target>[3]
56
-sS - This is a SYN stealth scan. It is less detectable than
a standard scan, but may take longer. Many modern
firewalls can detect an –sS scan.
-sn - This is a ping scan. This will disable port scanning,
and will only check to see if the host is online.
-O - This is an operating system scan. The scan will
attempt to determine the operating system of the target.
-A - This variable enables several of the most commonly
used scans: OS detection, version detection, script
scanning, and traceroute.
-F - This enables fast mode, and will reduce the number
of ports scanned.
-v - This will show more information in your results,
making them easier to read.
Output the scan to an XML file. You can set your scan results to
be outputted as an XML file so that you can easily read them in any web
browser. To do this, you will need to use the -oX variable, as well as set a
filename for the new XML file. A completed command would look similar
to nmap –oX Scan Results.xml <target>.
57
The XML file will be saved to whatever your current
working location is.
58
59
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.EXPERIMENT1:
60
Column 1 represents event type (s: send, r: receive, d: drop, f: forward)
Column 11 gives the reason for a packet drop and the various reasons
possible for a packet drop are as follows.
61
STA drop due to MAC invalid state
BSY drop due to MAC busy
NRTE drop due to no route available
LOOP drop due to routing loop
TTL drop due to TTL=0
TOUT drop due to packet expired
IFQ drop due to no buffer space in IFQ
ARP dropped ARP
OUT dropped by base stations
62