Data Communication and Computer Networks Practical File: Submitted By: Cteamcoders
Data Communication and Computer Networks Practical File: Submitted By: Cteamcoders
AND
COMPUTER NETWORKS
PRACTICAL FILE
Submitted by:
CTeamCoders
INDEX
AIM
Write a program that reads an IP address in dotted decimal form and determine
whether the address is of Class type A, B, C, D or E.
THEORY
An IP address is a 32 bit address that uniquely and universally defines the
connection of a device to the internet. It is a logical address in the network layer
of TCP/IP protocol suite.
We can find the class of an address when given the address in binary notation or
dotted decimal notation. If the address is given in binary notation, the first few
bits can immediately tell us the class of the address. If the address is given in
dotted decimal notation, the first byte defines the class.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
char ip[15],a[15];
int p,i=-1,j=-1;
cout<<"Enter the IP address: ";
gets(ip);
do
{
a[++j]=ip[++i];
}while(ip[i]!='.');
p=atoi(a);
cout<<"\nThe first byte of IP address is:"<<p<<”\n”;
if(p>0 && p<=127)
cout<<"\nThe IP address is of type CLASS A";
else
if(p>=128 && p<=191)
cout<<"\nThe IP address is of type CLASS B";
else
if(p>=192 && p<=223)
cout<<"\nThe IP address is of type CLASS C";
else
if(p>=224 && p<=239)
cout<<"\nThe IP address is of type CLASS D";
else
if(p>=240 &&p<=255)
cout<<"\nThe IP address is of type CLASS E";
else
cout<<"\nInvalid IP address";
getch();
}
OUTPUT
AIM
Write a program that translates a 32 bit IP address to dotted decimal notation
and a dotted decimal IP address to binary notation.
CODING
#include<iostream.h>
#include <stdio.h>
#include<stdlib.h>
#include <conio.h>
#include<string.h>
#include<math.h>
#include<process.h>
void decimal_to_binary()
{
char ip[15],a[15],b[15],c[15],d[15];
int p,q,r,s,t,aaa,bbb,ccc,ddd;
int k=-1,i=-1,j=-1,h=-1,w=-1,fla=0;
cout<<"\nEnter the IP Address: ";
gets(ip);
do
{
a[++j]=ip[++i];
}while(ip[i]!='.');
p=atoi(a);
do
{
b[++k]=ip[++i];
}while(ip[i]!='.');
q=atoi(b);
do
{
c[++h]=ip[++i];
}while(ip[i]!='.');
r=atoi(c);
do
{
d[++w]=ip[++i];
}while(ip[i]!='.');
s=atoi(d);
if(p>=0 && p<=255)
{
if(q>=0 && q<=255)
{
if(r>=0 && r<=255)
{
if(s>=0 && s<=255)
{
fla=1;
cout<<"\nFirst byte: "<<p;
cout<<"\nSecond byte: "<<q;
cout<<"\nThird byte: "<<r;
cout<<"\nFourth byte: "<<s<<"\n";
}
}
}
}
else
{
fla=0;
}
int e=7,f=7,g=7,v=7;
int aa[7],bb[7],cc[7],dd[7];
if(fla==1)
{
cout<<"\n\nConverted IP address is\n\n";
for(t=0;t<7;t++)
aa[t]=0;
do
{
aaa=p%2;
aa[e]=aaa;
e--;
p=p/2;
}while(p!=0);
for(t=0;t<=7;t++)
cout<<aa[t];
cout<<" ";
for(t=0;t<7;t++)
bb[t]=0;
do
{
bbb=q%2;
bb[f]=bbb;
f--;
q=q/2;
}while(q!=0);
for(t=0;t<=7;t++)
cout<<bb[t];
cout<<" ";
for(t=0;t<7;t++)
cc[t]=0;
do
{
ccc=r%2;
cc[g]=ccc;
g--;
r=r/2;
}while(r!=0);
for(t=0;t<=7;t++)
cout<<cc[t];
cout<<" ";
for(t=0;t<7;t++)
dd[t]=0;
do
{
ddd=s%2;
dd[v]=ddd;
v--;
s=s/2;
}while(s!=0);
for(t=0;t<=7;t++)
cout<<dd[t];
}
else
{
cout<<"\nInvalid IP address";
return;
}
}
void binary_to_decimal()
{
int i,j,k,w=-1,ipaddr[3];
char ip[32],ipad[4][8];
cout<<"\nEnter the IP address in binary form: \n";
gets(ip);
k=strlen(ip);
if(k!=32)
{
cout<<"\nInvalid IP address";
return;
}
for(i=0;i<32;i++)
{
if(ip[i]!='0' && ip[i]!='1')
{
cout<<"\nInvalid IP address";
return;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
ipad[i][j]=ip[++w];
}
}
for(i=0;i<4;i++)
{
if(i==0)
cout<<"\nFirst: ";
if(i==1)
cout<<"\nSecond: ";
if(i==2)
cout<<"\nThird: ";
if(i==3)
cout<<"\nFouth: ";
for(j=0;j<8;j++)
{
cout<<ipad[i][j];
}
}
for(i=0;i<4;i++)
{
ipaddr[i]=0;
for(j=0;j<8;j++)
{
ipaddr[i]*=2;
if(ipad[i][j]=='1')
ipaddr[i]++;
}
}
cout<<"\n\nConverted IP address is\n";
cout<<ipaddr[0]<<"."<<ipaddr[1]<<"."<<ipaddr[2]<<"."<<ipaddr[3];
}
void main()
{
clrscr();
int choice;
char ch;
do
{
cout<<"\nMENU";
cout<<"\n1. Convert IP Address from Binary notation to Dotted
Decimal notation";
cout<<"\n2. Convert IP Address from Dotted Decimal notation to
Binary notation";
cout<<"\n3. Exit from the program";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:binary_to_decimal();
break;
case 2:decimal_to_binary();
break;
case 3:exit(0);
default: cout<<"\nWrong choice";
}
cout<<"\n\nDo You Want To Continue(Y/N): ";
cin>>ch;
}while(ch=='Y'||ch=='y');
}
OUTPUT
MENU
1. Convert IP Address from Binary notation to Dotted Decimal notation
2. Convert IP Address from Dotted Decimal notation to Binary notation
3. Exit from the program
Enter your choice: 1
Converted IP address is
170.255.85.10
MENU
1. Convert IP Address from Binary notation to Dotted Decimal notation
2. Convert IP Address from Dotted Decimal notation to Binary notation
3. Exit from the program
Enter your choice: 2
Converted IP address is
MENU
1. Convert IP Address from Binary notation to Dotted Decimal notation
2. Convert IP Address from Dotted Decimal notation to Binary notation
3. Exit from the program
Enter your choice: 3
PRACTICAL 3
AIM
Write a program that reads an 8 bit string and generates its hamming code.
THEORY
In telecommunication, a Hamming code is a linear error-correcting code named
after its inventor, Richard Hamming. Hamming codes can detect up to two
simultaneous bit errors, and correct single-bit errors; thus, reliable
communication is possible when the Hamming distance between the transmitted
and received bit patterns is less than or equal to one. By contrast, the
simple parity code cannot correct errors, and can only detect an odd number of
errors.
Hamming code gives the exact position where the bits are toggled and then it
can be corrected by toggling it again.
The combination used to calculate each of the four P values for an 8 bit data
stream are as follows:
P1: 1,3,5,7,9,11…
P2: 2,3,6,7,10,11…
P3: 4,5,6,7,12…
P4: 8,9,10,11,12…
Firstly we place each bit of the original code in its appropriate position in the 12
bit unit. In subsequent steps we calculate the even parities for various bit
combinations. Parity value for each combination is the value of the corresponding
P value. Example: P1 value is such as to provide an even parity for a
combination of bits 3,5,7,9,11. Then the P value is placed at the specified
position.
CODING
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int bs[8],j=-1,i;
char p1,p2,p3,p4,db1[8],db2[12];
char q1[7],q2[6],q3[5],q4[5];
int a1=0,c=0,co=0,cou=0,count=0;
cout<<"\nEnter the 8 bit data stream: ";
gets(db1);
for(i=0;i<12;i++)
{
db2[i]='0';
}
db2[0]='2';
db2[1]='2';
db2[3]='2';
db2[7]='2';
for(i=0;i<12;i++)
{
if(db2[i]=='0')
db2[i]=db1[++j];
}
for(i=0;i<6;i++)
{
q1[i]=db2[a1];
a1+=2;
}
for(i=0;i<6;i++)
{
if(q1[i]=='1')
c++;
}
if(c%2==0)
db2[0]='0';
else
db2[0]='1';
q2[0]=db2[1];
q2[1]=db2[2];
q2[2]=db2[5];
q2[3]=db2[6];
q2[4]=db2[9];
q2[5]=db2[10];
for(i=0;i<6;i++)
{
if(q2[i]=='1')
co++;
}
if(co%2==0)
db2[1]='0';
else
db2[1]='1';
q3[0]=db2[3];
q3[1]=db2[4];
q3[2]=db2[5];
q3[3]=db2[6];
q3[4]=db2[11];
cou=0;
for(i=0;i<5;i++)
{
if(q3[i]=='1')
cou++;
}
if(cou%2==0)
db2[3]='0';
else
db2[3]='1';
q4[0]=db2[7];
q4[1]=db2[8];
q4[2]=db2[9];
q4[3]=db2[10];
q4[4]=db2[11];
for(i=0;i<5;i++)
{
if(q4[i]=='1')
count++;
}
if(count%2==0)
db2[7]='0';
else
db2[7]='1';
cout<<"\nHamming code is:";
for(i=0;i<12;i++)
cout<<db2[i];
getch();
}
OUTPUT
Enter the 8 bit data stream: 01100111
PRACTICAL 4
AIM
Write a program that implements bit stuffing method for framing.
THEORY
In data transmission and telecommunication, bit stuffing (also known as positive
justification) is the insertion of no information bits into data. Stuffed bits should
not be confused with overhead bits.
Bit stuffing is used for various purposes, such as for bringing bit streams that do
not necessarily have the same or rationally related bit rates up to a common rate,
or to fill buffers or frames. The location of the stuffing bits is communicated to the
receiving end of the data links, where these extra bits are removed to return the
bit streams to their original bit rates or form. Bit stuffing may be used to
synchronize several channels before multiplexing or to rate-match two single
channels to each other.
Bit stuffing does not ensure that the payload is intact (i.e. not corrupted by
transmission errors); it is merely a way of attempting to ensure that the
transmission starts and ends at the correct places. Error detection and correction
techniques are used to check the frame for corruption after its delivery and, if
necessary, the frame will be resent.
Zero-bit insertion
It is a particular type of bit stuffing (in the latter sense) used in some data
transmission protocols. It is done to ensure that the Flag byte doesn't incidentally
appear in a data frame. The name relates to the insertion of only 0 bits. No 1 bits
are inserted to limit sequences of 0 bits.
The bit sequence "01111110" containing six adjacent 1 bits is commonly used as
a "Flag byte". To ensure that this pattern never appears in normal data, a 0 bit is
stuffed after every five 1 bits in the data.
CODING
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char db[50],j,l,i=0,count=0;
cout<<"Enter the data bit stream(max 50 bits): ";
gets(db);
cout<<"\nAfter bit stuffing: ";
l=strlen(db);
while (i<l)
{
if(db[i]=='1')
{
i++;
count++;
if(count==5)
{
for(j=l;j>i;j--)
db[j]=db[j-1];
db[i]='0';
}
}
else
{
i++;
count=0;
}
}
for(i=0;i<l;i++)
cout<<db[i];
getch();
}
OUTPUT
Enter the data bit stream(max 50 bits): 0101111111110001
PRACTICAL 5
AIM
To create Straight-through, Cross-over and Roll-over cables.
EQUIPMENTS USED
RJ45, crimper, stripper, cable, knife, tester.
PROCEDURE
1. Pull the cable off the reel to the desired length and cut it.
2. Start on one end and strip the cable jacket off (about 1 inch) using a
stripper or a knife.
3. Spread, untwist the pairs and arrange the wires in the order of the desired
cable end. Flatten the end between your thumb & forefinger, then trim the
ends of the wire so that they are even with one another leaving only half-
inch in wire length.
4. Hold the RJ45 plug; push the wires firmly into the plug. Inspect each wire
is flat, even at the front of the plug, carefully hold the wire & firmly crimp
the RJ45 with the crimper.
5. Test the Ethernet cable by tester through the following scheme:
Straight through
END 1 END 2
1. Green-white Green-white
2. Green Green
3. Orange-white Orange-white
4. Blue Blue
5. Blue-white Blue-white
6. Orange Orange
7. Brown-white Brown-white
8. Brown Brown
Cross Over
END 1 END 2
1. Green-white Orange-white
2. Green Orange
3. Orange-white Green-white
4. Blue Blue
5. Blue-white Blue-white
6. Orange Green
7. Brown-white Brown-white
8. Brown Brown
Roll over
END 1 END 2
1. Green-white Brown
2. Green Brown-white
3. Orange-white Orange
4. Blue Blue-white
5. Blue-white Blue
6. Orange Orange-white
7. Brown-white Green
8. Brown Green-white
PRECAUTIONS
1. Ensure that wire does not have any cut.
2. Take care of your fingers while cutting.
3. While stripping don’t press the crimper too hard.
CONCLUSION
The Ethernet cable was working perfectly.
PRACTICAL 6
AIM
Implementation of some LINUX commands.
COMMANDS
1. hostname
The hostname command is used to set or display the Linux system's hostname.
SYNTAX
hostname
Example: hostname
OUTPUT:
your-vm1nwo8bv9
2. ipconfig
It allows you to get the IP address information of a Windows computer. It also
allows some control over active TCP/IP connections.
SYNTAX
Ipconfig
Example: ipconfig
OUTPUT:
Ethernet adapter Local Area Connection:
3. netstat
Shows network status.
SYNTAX
netstat [-e] [-n] [-o] [-r] [-s] [-v]
Example 2: netstat –e
OUTPUT:
Interface Statistics
Received Sent
Bytes 34037036 7113461
Unicast packets 54278 53911
Non-unicast packets 1486 246
Discards 0 0
Errors 0 8
Unknown protocols 15
4. tracert
Print the route packets take to network host.
SYNTAX
tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name
Trace complete.
Example: arp –a
OUTPUT:
Interface: 192.168.1.2 --- 0x2
Internet Address Physical Address Type
192.168.1.1 00-1e-40-53-65-1e dynamic
192.168.1.2 00-aa-00-62-c6-09 static
192.168.1.3 00-40-2b-2c-4a-35 static
6. ping
Sends ICMP echo_request packets to network hosts.
SYNTAX:
ping [-t] [-a] [-i TTL] [-v TOS] [-r count] [-w timeout] target_name
7. finger
Lists information about the user.
SYNTAX:
finger [-b] [-f] [-h] [-i] [-l] [-m] [-p] [-q] [-s] [-w] [username]
-b : Suppress printing the user's home directory and shell in a long format
printout.
-f : Suppress printing the header that is normally printed in a non-long format
printout.
-h : Suppress printing of the .project file in a long format printout.
-i : Force "idle" output format, which is similar to short format except that only the
login name, terminal, login time, and idle time are printed.
-l : Force long output format.
Example: finger
OUTPUT:
Login Name Tty Idle Login Time Where
root Superuser *02 344d Thu Sep 3 10:24
root Superuser p0 12d Thu Sep 3 10:24
student *p1 2 Tue Sep 15 11:55 10.0.13.241
student *p2 2 Tue Sep 15 12:32 10.0.12.65
student *p3 Tue Sep 15 12:38 10.0.13.142
student *p4 1 Tue Sep 15 11:55 10.0.13.179
student *p5 Tue Sep 15 12:37 10.0.12.152
student *p6 Tue Sep 15 12:29 10.0.12.122
student *p7 Tue Sep 15 12:27 10.0.13.228
student *p8 1 Tue Sep 15 12:24 10.0.13.248
student *p9 7 Tue Sep 15 12:27 10.0.13.206
student *p11 Tue Sep 15 11:56 10.0.13.199
student *p12 13 Tue Sep 15 12:05 10.0.13.157
student *p13 3 Tue Sep 15 12:25 10.0.13.151
student *p14 1 Tue Sep 15 11:55 10.0.12.96
student *p15 2 Tue Sep 15 12:33 10.0.12.240
student *p16 1 Tue Sep 15 12:26 10.0.13.231
student *p17 8 Tue Sep 15 11:56 10.0.12.82
student *p18 Tue Sep 15 12:08 10.0.13.54
student *p19 Tue Sep 15 12:34 10.0.12.81
student *p20 Tue Sep 15 12:25 10.0.13.249
student *p21 39 Tue Sep 15 11:56 10.0.12.115
student *p22 13 Tue Sep 15 11:56 10.0.13.149
student *p23 Tue Sep 15 12:38 10.0.43.8
student *p24 2 Tue Sep 15 11:59 10.0.13.182
student *p25 6 Tue Sep 15 11:57 10.0.13.93
student *p26 Tue Sep 15 12:38 10.0.13.108
student *p27 Tue Sep 15 12:29 10.0.13.209
student *p29 4 Tue Sep 15 12:26 10.0.13.95
student *p30 Tue Sep 15 12:26 10.0.12.212
Example 2: finger -i student
OUTPUT
Login Tty Login Time Idle
student ttyp1 Tue Sep 15 11:55
student ttyp2 Tue Sep 15 12:39 6 minutes 15 seconds
student ttyp3 Tue Sep 15 12:39 4 minutes 17 seconds
student ttyp4 Tue Sep 15 11:55
student ttyp5 Tue Sep 15 12:43 2 minutes 55 seconds
student ttyp6 Tue Sep 15 12:43 5 minutes 25 seconds
student ttyp7 Tue Sep 15 12:27 6 minutes 1 second
student ttyp9 Tue Sep 15 12:46
student ttyp10 Tue Sep 15 12:39 2 minutes 55 seconds
student ttyp11 Tue Sep 15 11:56 30 seconds
student ttyp12 Tue Sep 15 12:41 2 minutes 37 seconds
student ttyp13 Tue Sep 15 12:25
student ttyp14 Tue Sep 15 11:55
student ttyp15 Tue Sep 15 12:33 3 minutes 24 seconds
student ttyp16 Tue Sep 15 12:41
student ttyp17 Tue Sep 15 12:43
student ttyp18 Tue Sep 15 12:08
student ttyp19 Tue Sep 15 12:42
student ttyp20 Tue Sep 15 12:25
student ttyp21 Tue Sep 15 11:56 49 minutes
student ttyp22 Tue Sep 15 11:56 23 minutes
student ttyp23 Tue Sep 15 12:38
student ttyp24 Tue Sep 15 11:59 8 minutes 3 seconds
student ttyp25 Tue Sep 15 11:57 7 minutes 17 seconds
student ttyp26 Tue Sep 15 12:38
student ttyp27 Tue Sep 15 12:29 3 minutes 24 seconds
student ttyp28 Tue Sep 15 12:40 30 seconds
student ttyp29 Tue Sep 15 12:26
student ttyp30 Tue Sep 15 12:43
student ttyp31 Tue Sep 15 12:43 1 minute 36 seconds
student ttyp34 Tue Sep 15 12:23 3 minutes 24 seconds
student ttyp36 Tue Sep 15 12:26 3 minutes 39 seconds
student ttyp37 Tue Sep 15 12:45
8. who am i
Shows who is logged on
SYNTAX:
who am i
Example: who am i
OUTPUT:
student ttyp23 Sep 15 12:38
9. who
Show who all are logged on.
SYNTAX:
who
Example: who
OUTPUT:
root tty02 Sep 3 10:24
root ttyp0 Sep 3 10:24
student ttyp1 Sep 15 11:55
student ttyp2 Sep 15 12:32
student ttyp3 Sep 15 12:39
student ttyp4 Sep 15 11:55
student ttyp5 Sep 15 12:37
student ttyp7 Sep 15 12:27
student ttyp8 Sep 15 12:24
student ttyp9 Sep 15 12:27
student ttyp10 Sep 15 12:39
student ttyp11 Sep 15 11:56
student ttyp13 Sep 15 12:25
student ttyp14 Sep 15 11:55
student ttyp15 Sep 15 12:33
student ttyp16 Sep 15 12:26
student ttyp17 Sep 15 11:56
student ttyp18 Sep 15 12:08
student ttyp19 Sep 15 12:34
student ttyp20 Sep 15 12:25
student ttyp21 Sep 15 11:56
student ttyp22 Sep 15 11:56
student ttyp23 Sep 15 12:38
student ttyp24 Sep 15 11:59
student ttyp25 Sep 15 11:57
student ttyp26 Sep 15 12:38
student ttyp27 Sep 15 12:29
student ttyp29 Sep 15 12:26
student ttyp32 Sep 15 12:38
student ttyp34 Sep 15 12:23
student ttyp36 Sep 15 12:26
student ttyp37 Sep 15 12:28