Вы находитесь на странице: 1из 30

DATA COMMUNICATION

AND
COMPUTER NETWORKS
PRACTICAL FILE

Submitted by:
Arpita Srivastava
CS2 497
Btech CS & E
INDEX

S.No. PROGRAM REMARK


PRACTICAL 1

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.

Classful Addressing: In Classful addressing, the address space is divided into


five classes A, B, C, D and E. Each class occupies some part of the address
space.
Class A is identified by the leading bit of address which is always 0. Class
A address has 8 bits of network number and 24 bits of host number.
Class B addresses has 16 bits of network number and 16 bits of host
number. It is identified by the first two bits of network number which are 10.
Class C address has 24 bits of network and 8 bits of host number. It is
identified by the first three bits of network number which are 110.
Class D address is used for multicasting. It is identified by the first four bits
which are 1110 .There is no host number. The rest 28 bits identifies the multicast
group.
Class E address is reserved for experimental use and is identified by 1111
as the first four bits of the address.

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.

BINARY NOTATION (first few bits)


Class A 0
Class B 10
Class C 110
Class D 1110
Class E 1111

DOTTED DECIMAL (first byte)


Class A 0 - 127
Class B 18 - 191
Class C 192 - 223
Class D 224 - 239
Class E 240 – 255
CODING

#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

Enter the IP address: 129.42.34.87

The first byte of IP address is: 129

The IP address is of type CLASS B


PRACTICAL 2

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

Enter the IP address in binary form:


10101010111111110101010100001010

First byte: 10101010


Second byte: 11111111
Third byte: 01010101
Fourth: 00001010

Converted IP address is
170.255.85.10

Do You Want To Continue(Y/N): y

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

Enter the IP Address: 170.255.85.10

First byte: 170


Second byte: 255
Third byte: 85
Fourth byte: 10

Converted IP address is

10101010 11111111 01010101 00001010

Do You Want To Continue(Y/N): y

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.

Hamming rule: D+P+1<=2p


where D is data bit
P is parity bit
Hamming code = D+P.

P is added in the D at the following positions:


20,21,22,23,,…

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

Hamming code is: 010111010111


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

After bit stuffing: 01011111011110001


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

BASIC COMMANDS

1. hostname
The hostname command is used to show or set a computer's host name and
domain name i.e. displays system identity name. It is one of the most basic of the
network administrative utilities
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:

Connection-specific DNS Suffix . :


IP Address . . . . . . . . . . . . : 192.168.1.3
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

3. netstat
It is a command-line tool that displays network connections (both incoming and
outgoing), routing tables, and a number of network interface statistics.It is used
for finding problems in the network and to determine the amount of traffic on the
network as a performance measurement.
SYNTAX
netstat [-e] [-n] [-o] [-r] [-s] [-v]

-e : Displays Ethernet statistics. This may be combined with the –s option.


-n : Displays addresses and port numbers in numerical form.
-o : Displays the owning process ID associated with each connection.
-r : Displays the routing table.
-a : Displays all connections and listening ports.
-v : When used in conjunction with -b, will display sequence of components
involved in creating the connection or listening port for all executables.

Example 1: netstat
OUTPUT

Active Connections
Proto Local Address Foreign Address State
TCP your-vm1nwo8bv9:1302 localhost:1303 ESTABLISHED
TCP your-vm1nwo8bv9:1303 localhost:1302 ESTABLISHED
TCP your-vm1nwo8bv9:1311 localhost:1312 ESTABLISHED
TCP your-vm1nwo8bv9:1312 localhost:1311 ESTABLISHED
TCP your-vm1nwo8bv9:3133 ty-in-f19.google.com:http TIME_WAIT
TCP your-vm1nwo8bv9:3139 ty-in-f19.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3160 ty-in-f113.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3161 ty-in-f113.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3162 ty-in-f113.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3163 ty-in-f113.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3164 ty-in-f113.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3165 ty-in-f104.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3170 ty-in-f156.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3171 ty-in-f148.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3172 available.above.net:http ESTABLISHED
TCP your-vm1nwo8bv9:3173 ty-in-f148.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3174 64.236.76.160:http TIME_WAIT
TCP your-vm1nwo8bv9:3175 125.252.226.33:http ESTABLISHED
TCP your-vm1nwo8bv9:3176 phl-te.tacoda.net:http TIME_WAIT
TCP your-vm1nwo8bv9:3182 ty-in-f139.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3186 redirect.funpic.org:http TIME_WAIT
TCP your-vm1nwo8bv9:3195 ty-in-f19.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3196 ty-in-f19.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3197 ty-in-f19.google.com:http ESTABLISHED
TCP your-vm1nwo8bv9:3203 222.186.31.169:http SYN_SENT

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
Traceroute, also called tracepath, tracert or trace route, is a network tool used to
determine the "path" packets take from one IP address to another. It provides the
hostname, IP address, and the response time to a ping. Our visual traceroute
also includes a map displaying each of the hops.
SYNTAX
tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

-d : Do not resolve addresses to hostnames.


-h maximum_hops : Maximum number of hops to search for target.
-j host-list : Loose source route along host-list.
-w timeout : Wait timeout milliseconds for each reply.

Example: tracert 192.168.1.2


OUTPUT:
Tracing route to your-vm1nwo8bv9 [192.168.1.2]
over a maximum of 30 hops:

1 <1 ms <1 ms <1 ms your-vm1nwo8bv9 [192.168.1.2]

Trace complete.

Example 2: tracert google.com


OUTPUT:
Tracing route to google.com [74.125.67.100]
over a maximum of 30 hops:

1 <1 ms 1 ms <1 ms 192.168.1.1


2 32 ms 34 ms 32 ms ABTS-North- Static 018.230.160.122.
airtelbroadband.in [122.160.230.18]
3 32 ms 32 ms 32 ms ABTS-North-Static-021.230.160.122.
airtelbroadband.in [122.160.230.21]
4 32 ms 32 ms 32 ms ABTS-North-Static-158.230.160.122.
airtelbroadband.in [122.160.230.158]
5 32 ms 31 ms 31 ms 125.19.22.145
6 83 ms 82 ms 82 ms 125.21.167.25
7 84 ms 84 ms 84 ms 72.14.196.101
8 89 ms 89 ms 89 ms 72.14.232.112
9 369 ms 344 ms 343 ms 66.249.94.74
10 340 ms 340 ms 346 ms 72.14.232.115
11 345 ms 368 ms 346 ms 209.85.255.37
12 337 ms 337 ms 342 ms 216.239.43.212
13 344 ms 341 ms 339 ms 216.239.43.81
14 343 ms 343 ms 384 ms 72.14.239.90
15 339 ms 342 ms 346 ms 72.14.239.131
Trace completed
5. arp -a
Displays and modifies the IP-to-Physical address translation tables used by
address resolution protocol (ARP). ARP is used to perform IP address resolution
which is the linking of IP addresses to MAC (Media Access Control) hardware
addresses. ARP uses a broadcast to do this by asking the host that has the given
IP address to respond to the broadcast with its MAC address.
SYNTAX:
arp -a

-a : Displays current ARP entries by interrogating the current protocol data.

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
The PING command is used to test the connection and latency between two
network connections. These connections can be either in a local area network or
a wide area network or the internet as a whole. The PING command sends
packets of information to a specified IP Address and then measures the time it
takes to get a response from the specified computer or device.
SYNTAX:
ping [-t] [-a] [-i TTL] [-v TOS] [-r count] [-w timeout] target_name
-t : Ping the specified host until stopped.
-a : Resolve addresses to hostnames.
-i TTL : Time To Live.
-v TOS : Type Of Service.
-r count : Record route for count hops.
-w timeout : Timeout in milliseconds to wait for each reply.

Example : ping 192.168.1.12


OUTPUT:
Pinging 192.168.1.12 with 32 bytes of data:

Reply from 192.168.1.12: bytes=32 time<1ms TTL=128


Reply from 192.168.1.12: bytes=32 time<1ms TTL=128
Reply from 192.168.1.12: bytes=32 time<1ms TTL=128
Reply from 192.168.1.12: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.1.12:


Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms.

7. finger
Displays information about a user on a specified system running the Finger
service. Output varies based on the remote system.

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.159

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

8. who am i
It is a command found on most Unix-like operating systems. It prints the effective
userid (username) of the current user when invoked.
SYNTAX:
who am i

Example: who am i
OUTPUT:
student ttyp23 Sep 15 12:38

9. who
Displays information about all the users currently logged onto the system. The
user name, terminal number and the date and time that each user logged onto the
system.
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:39
PRACTICAL 7

AIM
Write a program for implementing pure and slotted ALOHA.

THEORY
The ALOHA protocol is an OSI layer 2 protocol for LAN networks with broadcast
topology. It was designed to establish communication among the ice lands using
a packet radio system. Essentially it allowed many stations to broadcast at any
time, if two signals collided, so be it. Each station would simply wait a random
time and try again.

PURE ALOHA
The pure Aloha is the basic protocol in the family of Aloha protocols. It considers
a single hop system with an infinite population generating packets of equal
length. The channel is error free without capture: whenever a packet of
transmission does not interfere with any other packet transmission. The
transmitted packet is received correctly while if two of more packet transmissions
overlap in time, a collision is caused and none of the colliding packets is received
correctly and they have to be retransmitted. At the end of every transmission
every user knows whether the transmission was successful or collision took
place.
Pure Aloha had a maximum throughput of about 18.4%. This means that about
81.6% of the total available bandwidth was essentially wasted due to losses from
packet detection.

SLOTTED ALOHA
The channel bandwidth is a continuous stream of slots whose length is the time
necessary to transmit one packet. A station with a packet to send will transmit on
the next available slot boundary. In the event of a collision, each station involved
in the collision retransmits at some random time in order to reduce the possibility
of recollision. Obviously the limits imposed which govern the random
retransmission of the packet will have an effect on the delay associated with
successful packet delivery. If the limit is too short, the probability of recollision is
high. If the limit is too long the probability of recollision lessens but there is
unnecessary delay in the retransmission.
Slotted Aloha, which introduced discrete timeslots and increased the maximum
throughput to 36.8%. A station can send only at the beginning of a timeslot, and
thus collisions are reduced.

CODING

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
clrscr();
float g,s;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(55,442,575,442);
line(55,215,55,442);
line(45,225,55,215);
line(65,225,55,215);
line(565,452,575,442);
line(565,432,575,442);
for (g=0;g<=3.3;g+=0.001)
{
delay(2);
s=-g*exp(-2*g);
putpixel(58+g*150,(440+s*500),CYAN);
s=-g*exp(-1*g);
putpixel(58+g*150,440+s*500,MAGENTA);
}
settextstyle(2,0,5);
outtextxy(52,444,"0");
outtextxy(126,444,"0.5");
outtextxy(200,444,"1.0");
outtextxy(278,444,"1.5");
outtextxy(357,444,"2.0");
outtextxy(537,444,"3.0");
delay(200);
settextstyle(2,0,5);
settextjustify(1,1);
outtextxy(35,400,"0.10");
outtextxy(35,345,"0.20");
outtextxy(35,290,"0.30");
outtextxy(35,235,"0.40");
delay(200);
line(286,442,286,436);
line(366,442,366,436);
line(546,442,546,436);
settextjustify(0,2);
setcolor(15);
delay(200);
outtextxy(400,410,"Pure ALOHA: S=Ge^-2G");
delay(200);
outtextxy(400,300,"Slotted ALOHA: S=Ge^-G");
delay(200);
outtextxy(190,460,"G (attempts per packet time)");
settextstyle(2,1,5);
outtextxy(2,210,"S (throughput per frame time)");
setlinestyle(3,3,1);
delay(200);
line(135,442,135,346);
line(135,348,55,348);
delay(200);
line(208,442,208,255);
line(208,256,55,256);
getch();
}
OUTPUT

Вам также может понравиться