Sunteți pe pagina 1din 40

Data Communication

and Computer
Networks
Practical File

Submitted By:

Manish Sharma
A2305216360
B.TECH(6CSE7X)
INDEX

CODE

MARKSMAX.
NO.EXPERIMENT

OBTAINEDMARKS
CATEGORY OF

ALLOTMENT DATE OF

EVALUATIONDATE OF

FACULTYSIGNATURE OF
ASSIGNMENT

NAME OF EXPERIMENT

1 MANDATOR LR Network Commands on Linux / Unix. 6


Y (15
EXPERIMEN )
2 T
Program to implement CYCLIC 6
REDUNDANCY CHECK (CRC).
3 Program to implement Bit Stuffing 6

4 Program to implement Hamming code. 6

5 Program to implement Byte Stuffing and 6


De- stuffing.

6 Program to implement Sliding Window 6


Protocol.

7 To establish straight configuration for 6


LAN

8 To establish crossover configuration for 6


LAN.
9 To establish rollover configuration for 6
LAN.

10 Program to translate 32 bit IP Address to 6


binary form

11 : Program to Find class A, B, C from 6


entered IP Address.
EXPERIMENT 1
AIM: Networks commands on UNIX/LINUX.
1. Ipconfig: ipconfig displays all current TCP/IP network configuration values and refreshes
Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) settings.

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

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

0. Traceroute: Traceroute, also called trace path, 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.

0. PathPing: It combines the functionality of Ping with that of Traceroute, by providing details
of the path between two hosts and Ping-like statistics for each node in the path based on
samples taken over a time period, depending on how many nodes are between the start and
end host. 

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

0. 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.
0. Ping -a:

0. Ping -l:

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

0. Whoami: It is a command found on most Unix-like operating systems. It prints the effective
userid (username) of the current user when invoked.
EXPERIMENT 2

AIM: Program to implement CYCLIC REDUNDANCY CHECK (CRC).

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>

// using namespace std;


void main() {
int i,j,keylen,msglen;
char input[100], key[30],temp[30],quot[100],rem[30],key1[30];
// clrscr();
printf("Enter Data: ");
gets(input);
printf("Enter Key: ");
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++)
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]);
printf("\nFinal data is: ");
for (i=0;i<msglen;i++)
printf("%c",input[i]);
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
getch();
}
Output:
EXPERIMENT 3
AIM: Program to implement Bit Stuffing.

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size :");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1 :");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1; a[k]==1 && k<n && count<5; k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After Bit Stuffing :");
for(i=0; i<j; i++)
printf("%d",b[i]);
getch();
}
Output:
EXPERIMENT 4
AIM: Program to implement Hamming code.

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

THEORY:

Hamming code is a set of error-correction codes that can be used to detect and correct the
errors that can occur when the data is moved or stored from the sender to the receiver. It
is technique developed by R.W. Hamming for error correction.
Redundant bits –
Redundant bits are extra binary bits that are generated and added to the information-carrying bits of
data transfer to ensure that no bits were lost during the data transfer.
The number of redundant bits can be calculated using the following formula:
Suppose the number of data bits is 7, then the number of redundant bits can be calculated using:
= 2^4 ≥ 7 + 4 + 1
Thus, the number of redundant bits= 4
Parity bits –
A parity bit is a bit appended to a data of binary bits to ensure that the total number of 1’s in the
data is even or odd. Parity bits are used for error detection. There are two types of parity bits:
1. Even parity bit:
In the case of even parity, for a given set of bits, the number of 1’s are counted. If that count is
odd, the parity bit value is set to 1, making the total count of occurrences of 1’s an even
number. If the total number of 1’s in a given set of bits is already even, the parity bit’s value is
0.
2. Odd Parity bit –
In the case of odd parity, for a given set of bits, the number of 1’s are counted. If that count is
even, the parity bit value is set to 1, making the total count of occurrences of 1’s an odd
number. If the total number of 1’s in a given set of bits is already odd, the parity bit’s value is
0.
General Algorithm of Hamming code –
The Hamming Code is simply the use of extra parity bits to allow the identification of an error.
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in binary
form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the least
significant
position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the
second position from
the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the third
position from
the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the
fourth position from
the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general, each parity bit covers all bits where the bitwise AND of the parity position and
the bit position is
non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is
odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.
Determining the position of redundant bits –
These redundancy bits are placed at the positions which correspond to the power of 2.
As in the above example:
1. The number of data bits = 7
2. The number of redundant bits = 4
3. The total number of bits = 11
4. The redundant bits are placed at positions corresponding to power of 2- 1, 2, 4, and 8
Suppose the data to be transmitted is 1011001, the bits will be placed as follows:

Determining the Parity bits –


1. R1 bit is calculated using parity check at all the bits positions whose binary representation
includes a 1 in the least significant position.
R1: bits 1, 3, 5, 7, 9, 11

To find the redundant bit R1, we check for even parity. Since the total number of 1’s in all the
bit positions corresponding to R1 is an even number the value of R1 (parity bit’s value) = 0
2. R2 bit is calculated using parity check at all the bits positions whose binary representation
includes a 1 in the second position from the least significant bit.
R2: bits 2,3,6,7,10,11
To find the redundant bit R2, we check for even parity. Since the total number of 1’s in all the
bit positions corresponding to R2 is odd the value of R2(parity bit’s value)=1
3. R4 bit is calculated using parity check at all the bits positions whose binary representation
includes a 1 in the third position from the least significant bit.
R4: bits 4, 5, 6, 7

To find the redundant bit R4, we check for even parity. Since the total number of 1’s in all the
bit positions corresponding to R4 is odd the value of R4(parity bit’s value) = 1
4. R8 bit is calculated using parity check at all the bits positions whose binary representation
includes a 1 in the fourth position from the least significant bit.
R8: bit 8,9,10,11

To find the redundant bit R8, we check for even parity. Since the total number of 1’s in all the
bit positions corresponding to R8 is an even number the value of R8(parity bit’s value)=0.

Thus, the data transferred is:

Error detection and correction –


Suppose in the above example the 6th bit is changed from 0 to 1 during data transmission, then it
gives new parity values in the binary number:

The bits give the binary number as 0110 whose decimal representation is 6. Thus, the bit 6 contains
an error. To correct the error the 6th bit is changed from 1 to 0.
Code:
#include<stdio.h>
void main() {
int data[10];
int dataatrec[10],c,c1,c2,c3,i;

printf("Enter 4 bits of data one by one\n");


scanf("%d",&data[0]);
scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);

//Calculation of even parity


data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");


for(i=0;i<7;i++)
printf("%d",data[i]);
printf("\n\nEnter received data bits one by one\n");
for(i=0;i<7;i++)
scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;

if(c==0) {
printf("\nNo error while transmission of data\n");
}
else {
printf("\nError on position %d",c);

printf("\nData sent : ");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\nData received : ");


for(i=0;i<7;i++)
printf("%d",dataatrec[i]);

printf("\nCorrect message is\n");

//if errorneous bit is 0 we complement it else vice versa


if(dataatrec[7-c]==0)
dataatrec[7-c]=1;
else
dataatrec[7-c]=0;

for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);
}
}
}
Output:

Conclusion: Hamming Code was successfully implemented.

EXPERIMENT 5
AIM: Program to implement Byte Stuffing and De- stuffing.

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

THEORY:

Byte stuffing –
A byte (usually escape character(ESC)), which has a predefined bit pattern is added to the data
section of the frame when there is a character with the same pattern as the flag. Whenever the
receiver encounters the ESC character, it removes from the data section and treats the next
character as data, not a flag.
But the problem arises when the text contains one or more escape characters followed by a flag. To
solve this problem, the escape characters that are part of the text are marked by another escape
character i.e., if the escape character is part of the text, an extra one is added to show that the
second one is part of the text.
Example:

Note – Point-to-Point Protocol (PPP) is a byte-oriented protocol.

Code:
#include<stdio.h>
#include<string.h>

int main()
{
char data[50],stuff[50],dstuff[50];
int i,j,cnt=1,fsize,dsize,frames,denter,loop,check=0;

printf("Enter data:- \n");


scanf("%s",data);

dsize=strlen(data);

printf("enter frame size \n");


scanf("%d",&fsize);

denter=fsize-2;
frames=(dsize/denter)+1;

loop=dsize+(frames*2);
printf("%d",loop);

j=0;
for(i=0;i<loop;i++)
{
if(i%fsize==0)
{
stuff[i]='x';
}
else if (i==(fsize*cnt)-1)
{
stuff[i]='x';
cnt++;
}
else
{
if(data[j]=='\0')
{
check=1;
break;
}
stuff[i]=data[j];
j++;
}
}
if(check==1)
stuff[loop-1]='x';

stuff[loop]='\0';
printf("the stuffed data is: %s \n",stuff);

//destuff
j=0;
for(i=0;i<loop;i++)
{
if(stuff[i]!='x')
{
dstuff[j] = stuff[i];
j++;
}
}
dstuff[j]='\0';
printf("\n\n destuffed data is :%s",dstuff);
return 0;
}
Output:

Conclusion: Byte Stuffing and De -Stuffing was successfully implemented.

EXPERIMENT 6
AIM: Program to implement Sliding Window Protocol.

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

THEORY:

Sliding window protocols are data link layer protocols for reliable and sequential delivery of data
frames. The sliding window is also used in Transmission Control Protocol.
In this protocol, multiple frames can be sent by a sender at a time before receiving an
acknowledgment from the receiver. The term sliding window refers to the imaginary boxes to hold
frames. Sliding window method is also known as windowing.
Working Principle
In these protocols, the sender has a buffer called the sending window and the receiver has buffer
called the receiving window.
The size of the sending window determines the sequence number of the outbound frames. If the
sequence number of the frames is an n-bit field, then the range of sequence numbers that can be
assigned is 0 to 2𝑛−1. Consequently, the size of the sending window is 2 𝑛−1. Thus in order to
accommodate a sending window size of 2 𝑛−1, a n-bit sequence number is chosen.
The sequence numbers are numbered as modulo-n. For example, if the sending window size is 4,
then the sequence numbers will be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and so on. The number of bits in the
sequence number is 2 to generate the binary sequence 00, 01, 10, 11.
The size of the receiving window is the maximum number of frames that the receiver can accept at a
time. It determines the maximum number of frames that the sender can send before receiving
acknowledgment.
Example
Suppose that we have sender window and receiver window each of size 4. So the sequence
numbering of both the windows will be 0,1,2,3,0,1,2 and so on. The following diagram shows the
positions of the windows after sending the frames and receiving acknowledgments.
Types of Sliding Window Protocols
The Sliding Window ARQ (Automatic Repeat reQuest) protocols are of two categories −

 Go – Back –  N ARQ
Go – Back – N ARQ provides for sending multiple frames before receiving the
acknowledgment for the first frame. It uses the concept of sliding window, and so is also
called sliding window protocol. The frames are sequentially numbered and a finite number
of frames are sent. If the acknowledgment of a frame is not received within the time period,
all frames starting from that frame are retransmitted.
 Selective Repeat ARQ
This protocol also provides for sending multiple frames before receiving the
acknowledgment for the first frame. However, here only the erroneous or lost frames are
retransmitted, while the good frames are received and buffered.
Code:

A) GO – BACK-N

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
int nf,N;
int no_tr=0;
srand(time(NULL));
cout<<"Enter the number of frames : ";
cin>>nf;
cout<<"Enter the Window Size : ";
cin>>N;
int i=1;
while(i<=nf)
{
int x=0;
for(int j=i;j<i+N && j<=nf;j++)
{
cout<<"Sent Frame "<<j<<endl;
no_tr++;
}
for(int j=i;j<i+N && j<=nf;j++)
{
int flag = rand()%2;
if(!flag)
{
cout<<"Acknowledgment for Frame "<<j<<endl;
x++;
}
else
{ cout<<"Frame "<<j<<" Not Received"<<endl;
cout<<"Retransmitting Window"<<endl;
break;
}
}
cout<<endl;
i+=x;
}
cout<<"Total number of transmissions : "<<no_tr<<endl;
return 0;
}

B) Selective Repeat
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int temp1,temp2,temp3,temp4,temp5,i,winsize=8,noframes,moreframes;
char c;
int receiver(int);
int simulate(int);
int nack(int);
temp4=0,temp1=0,temp2=0,temp3=0,temp5=0;
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
printf("\n number of frames is %d",noframes);
getch();
moreframes=noframes;
while(moreframes>=0)
{
temp1=simulate(winsize);
winsize=temp1;
temp4+=temp1;
if(temp>noframes)
temp4=noframes;
for(i=noframes-moreframes;i<=temp4;i++)
prinf("\nsending frame %d",i);
getch();
temp2=receiver(temp1);
temp3+=temp2;
if(temp3>noframes)
temp3=noframes;
temp2=nack(temp1);
temp5+=temp2;
if(temp5!=0)
{
printf("\n No of acknowledgement for the frame %d",temp5);
getch();
for(i=1;i<temp5;i++)
{
printf("\nRetransmitting frame %d",temp5);
getch();
}
moreframes=temp1;
if(winsize<=0)
winsize=8;
}
printf("\n end of sliding window protocol selective repeat");
getch();
}

int receiver(int temp1)


{
int i;
for(i=1;i<100;i++)

int i;
for(i=1;i<100;i++)
rand();
i=rand()%temp1;
return i;
}

int nack(int temp1)


{
int i;
for(i=1;i<100;i++)
rand();
i=rand()%temp1;
return i;
}

int simulate(int winsize)


{
int temp1,i;
for(i=1;i<50;i++)
temp1=rand();
if(temp1==0)
temp1=simulate(winsize);
i=temp1%winsize;
if(i==0)
return winsize;
else
return temp1%winsize;

}
}

C) STOP AND WAIT


#include<iostream>
#include <time.h>
#include <cstdlib>
#include<ctime>
#include <unistd.h>
using namespace std;
class timer {
private:
unsigned long begTime;
public:
void start() {
begTime = clock();
}
unsigned long elapsedTime() {
return ((unsigned long) clock() - begTime) / CLOCKS_PER_SEC;
}
bool isTimeout(unsigned long seconds) {
return seconds >= elapsedTime();
}
};
int main()
{
int frames[] = {1,2,3,4,5,6,7,8,9,10};
unsigned long seconds = 5;
srand(time(NULL));
timer t;
cout<<"Sender has to send frames : ";
for(int i=0;i<10;i++)
cout<<frames[i]<<" ";
cout<<endl;
int count = 0;
bool delay = false;
cout<<endl<<"Sender\t\t\t\t\tReceiver"<<endl;
do
{
bool timeout = false;
cout<<"Sending Frame : "<<frames[count];
cout.flush();
cout<<"\t\t";
t.start();
if(rand()%2)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
}
if(t.elapsedTime() <= seconds)
{
cout<<"Received Frame : "<<frames[count]<<" ";
if(delay)
{
cout<<"Duplicate";
delay = false;
}
cout<<endl;
count++;
}
else
{
cout<<"---"<<endl;
cout<<"Timeout"<<endl;
timeout = true;
}
t.start();
if(rand()%2 || !timeout)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
if(t.elapsedTime() > seconds )
{
cout<<"Delayed Ack"<<endl;
count--;
delay = true;
}
else if(!timeout)
cout<<"Acknowledgement : "<<frames[count]-1<<endl;
}
}while(count!=10);
return 0;
}
Output:
Conclusion: Sliding Window Protocol was successfully implemented.
EXPERIMENT 7
AIM: To establish straight configuration for LAN

EQUIPMENTS REQUIRED:-

1) 2 RJ -45 connectors

2) Twisted pair cable

3) Gripping or Crimping tool

4) SLT-Tool

COLOUR CODING:

1. Orange white

2. Orange

3. Green white

4. Blue

5. Blue white

6. Green

7. Brown white

8. Brown

STRAIGHT CONFIGURATION:

1---------------------------------------------1

2---------------------------------------------2

3---------------------------------------------3

4---------------------------------------------4

5---------------------------------------------5

6---------------------------------------------6

7---------------------------------------------7

8---------------------------------------------8

THEORY: A local area network (LAN) is a computer network that connects computers and devices in
a limited geographical area such as home, school, computer laboratory or office building. The
defining characteristics of LANs, in contrast to wide area networks (WANs), include their usually
higher data-transfer rates, smaller geographic area, and lack of a need for leased telecommunication
lines.

ARCNET, Token Ring and other technology standards have been used in the past, but Ethernet over
twisted pair cabling, and Wi-Fi are the two most common technologies currently in use.
PROCEDURE:-

The outer covering of the wire is peeled off and according to requirement the wires are inserted in
RJ-45 connector and punched with the help of punching tool after punching the wire is tested with
SLT( Side locator tool).

RESULT:-

The straight wiring for the LAN has been established and tested using SLT tool.

USE:-

This type of wiring is used for connecting to PC or Hub.


EXPERIMENT 8
AIM: To establish crossover configuration for LAN.
EQUIPMENTS REQUIRED: -
1) 2 RJ -45 connectors

2) Twisted pair cable

3) Gripping or Crimping tool

4) SLT-Tool

COLOUR CODING:
1. Orange white

2. Orange

3. Green white

4. Blue

5. Blue white

6. Green

7. Brown white

8. Brown

CROSSOVER CONFIGURATIONS:-
1---------------------------------------------3
2---------------------------------------------6
3---------------------------------------------1
4---------------------------------------------4
5---------------------------------------------5
6---------------------------------------------2
7---------------------------------------------7
8---------------------------------------------8

THEORY: A local area network (LAN) is a computer network that connects computers and devices in
a limited geographical area such as home, school, computer laboratory or office building. The
defining characteristics of LANs, in contrast to wide area networks (WANs), include their usually
higher data-transfer rates, smaller geographic area, and lack of a need for leased telecommunication
lines.

ARCNET, Token Ring and other technology standards have been used in the past, but Ethernet over
twisted pair cabling, and Wi-Fi are the two most common technologies currently in use.

PROCEDURE:-
The outer covering of the wire is peeled off and according to requirement the wires are inserted in
RJ-45 connector and punched with the help of punching tool after punching the wire is tested with
SLT (Side locator tool).
RESULT:-
The crossover wiring for the LAN has been established and tested using SLT tool.
USES:
This type of wiring is used for connecting PC to another PC.
EXPERIMENT 9

AIM: To establish rollover configuration for LAN.


EQUIPMENTS REQUIRED:-
1) 2 RJ -45 connectors

2) Twisted pair cable

3) Gripping or Crimping tool

4) SLT-Tool

COLOUR CODING:
1. Orange white

2. Orange

3. Green white

4. Blue

5. Blue white

6. Green

7. Brown white

8. Brown

ROLLOVER CONFIGURATION:-
1---------------------------------------------8
2---------------------------------------------7
3---------------------------------------------6
4---------------------------------------------5
5---------------------------------------------4
6---------------------------------------------3
7---------------------------------------------2
8---------------------------------------------1

THEORY: A local area network (LAN) is a computer network that connects computers and devices in
a limited geographical area such as home, school, computer laboratory or office building. The
defining characteristics of LANs, in contrast to wide area networks (WANs), include their usually
higher data-transfer rates, smaller geographic area, and lack of a need for leased telecommunication
lines.

ARCNET, Token Ring and other technology standards have been used in the past, but Ethernet over
twisted pair cabling, and Wi-Fi are the two most common technologies currently in use.

PROCEDURE:-
The outer covering of the wire is peeled off and according to requirement the wires are inserted in
RJ-45 connector and punched with the help of punching tool after punching the wire is tested with
SLT( Side locator tool).
RESULT:-
The rollover wiring for the LAN has been established and tested using SLT tool.
USE:-
This type of wiring is used for configuration of the router.
EXPERIMENT 10
AIM: Program to translate 32 bit IP Address to binary form

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

THEORY:

An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g.,
computer, printer) participating in a computer network that uses the Internet Protocol for
communication. An IP address serves two principal functions: host or network interface
identification and location addressing.

The designers of the Internet Protocol defined an IP address as a 32-bit number and this system,
known as Internet Protocol Version 4 (IPv4), is still in use today. However, due to the enormous
growth of the Internet and the predicted depletion of available addresses, a new addressing system
(IPv6), using 128 bits for the address, was developed in 1995.

Code:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int convert_binary(int a,int b,int c,int d);

int * convert_binary1(int a);

main()

int i,j; //loop index

int ip[4]; // array to store ip seperated by "."

int binary[32]; //store ip in binary

int *bin;

char *piece;

char input[20];

printf("\nEnter ip address:");
scanf("%s",input); //read ip as string

piece = strtok(input,"."); //split . seperated ip , first call to the function strtok will return first piece
in the string, subsequent calls to the function with null as first parameter will return subsequent
pieces

i=0;

do {

ip[i++]=atoi(piece); // atoi(string) converts string to integer, store pieced string into


integer array

piece=strtok(NULL,"."); // this is subsequent call

} while(piece && i<4);

for(j=0;j<4;j++) // loop through ips e.g 192.168.0.1 first loop will process ip[0] which has 192 stored

bin = convert_binary1( ip[j] ); //convert integer to binary , stored in integer array

for(i=0;i<8;i++)

binary[j*8+i]=bin[i]; // store converted binary into correct position in 32 binary array

for(i=0;i<32;i++)

if(i>0 && (i)%8==0) printf("."); //print a "." after printing 8 digits

printf("%d",binary[i]); //print binary values of given ip saved in this int array

printf("\n");

//takes an integer as input

//returns binary stored in integer array

int * convert_binary1(int a)

int i,j,k,l;

int *num=(int *)malloc(sizeof(int)*8); //allocating memory of 8 integers


for(i=0;i<=7;i++)

num[7-i]=a%2;

a=a/2;

return num;

int convert_binary(int a,int b, int c, int d)

int i,j,k,l;

int num[10];

for(i=0;i<=7;i++)

num[i]=a%2;

a=a/2;

//return(num);

for(i=7;i>=0;i--)

{printf("%d", num[i]);}printf(".");

for(j=0;j<=7;j++)

num[j]=b%2;

b=b/2;

for(j=7;j>=0;j--)

{printf("%d", num[j]);}printf(".");

for(k=0;k<=7;k++)

num[k]=c%2;

c=c/2;
}

for(k=7;k>=0;k--)

{printf("%d", num[k]);}printf(".");

for(l=0;l<=7;l++)

num[l]=d%2;

d=d/2;

for(l=7;l>=0;l--)

{printf("%d", num[l]);}

Output:

EXPERIMENT 11
AIM: Program to Find class A, B, C from entered IP Address.

PROGRAMMING LANGUAGE USED: C

IDE USED: DEV C++

THEORY:
CP/IP defines five classes of IP addresses: class A, B, C, D, and E. Each class has a range of valid IP
addresses. The value of the first octet determines the class. IP addresses from the first three classes
(A, B and C) can be used for host addresses. The other two classes are used for other purposes –
class D for multicast and class E for experimental purposes.

The system of IP address classes was developed for the purpose of Internet IP addresses assignment.
The classes created were based on the network size. For example, for the small number of networks
with a very large number of hosts, the Class A was created. The Class C was created for numerous
networks with small number of hosts.

Classes of IP addresses are:

For the IP addresses from Class A, the first 8 bits (the first decimal number) represent the network
part, while the remaining 24 bits represent the host part. For Class B, the first 16 bits (the first two
numbers) represent the network part, while the remaining 16 bits represent the host part. For Class
C, the first 24 bits represent the network part, while the remaining 8 bits represent the host part.

Code:

#include<iostream>
using namespace std;
/* CLASSES
A: 0 - 127 ( = 128 )
B: 128 - 191 ( = 64 )
C: 192 - 223 ( = 32 )
D: 224 - 239 ( = 16 )
E: 240 - 255 ( = 16 )
*/
int main()
{
// clrscr();
int a[4],i=0;

cout<<"Enter The IP address";


for(i=0;i<4;i++)
cin>>a[i];

cout<<"\n IP ADDRESS:"<<a[0];
cout<<"."<<a[1]<<"."<<a[2]<<"."<<a[3]<<"\n";

cout<<"The IP address is in Class: ";

if(a[0]>=0 && a[0]<=127)


cout<<"Class A";
if(a[0]>127 && a[0]<191)
cout<<"Class B";
if(a[0]>191 && a[0]<224)
cout<<"Class C";
if(a[0]>224 && a[0]<=239)
cout<<"Class D";
if(a[0]>239)
cout<<"Class E";
// getch();

return 1;
}
Output:

Conclusion: The program was successfully implemented.

S-ar putea să vă placă și