Computer Network Lab
Computer Network Lab
Computer Network Lab
Mission
The Department's mission is
To provide students and faculty with an open environment that
encourages professional and personal growth.
ASSIGNMENT 1:
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
Straight cable is a type of CAT5 with RJ-45 connectors at each end, and each has
the same pin out. It is in accordance with either the T568A or T568B standards.
It uses the same colour code throughout the LAN for consistency. This type of
twisted-pair cable is used in LAN to connect a computer or a network hub such
as a router. It is one of the most common types of network cable.
A Crossover cable is a type of CAT 5 where one end isT568A configuration and
the other end as T568BConfiguration. In this type of cable connection, Pin 1 is
crossed with Pin 3, and Pin 2 is crossed with Pin 6.
Crossover cable is used to connect two or more computing devices. The internal
wiring of crossover cables reverses the transmission and receive signals. It is
widely used to connect two devices of the same type: e.g., two computers or two
switches to each other.
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
ASSIGNMENT 2:
Switch – A switch is a multiport bridge with a buffer and a design that can
boost its efficiency (a large number of ports imply less traffic) and
performance. A switch is a data link layer device. The switch can perform error
checking before forwarding data, that makes it very efficient as it does not
forward packets that have errors and forward good packets selectively to
correct port only. In other words, switch divides collision domain of hosts,
but broadcast domain remains same.
Bridge – A bridge operates at data link layer. A bridge is a repeater, with add
on the functionality of filtering content by reading the MAC addresses of source
and destination. It is also used for interconnecting two LANs working on the
same protocol. It has a single input and single output port, thus making it a 2-
port device.
Types of Bridges:
Transparent Bridges: - These are the bridge in which the stations are
completely unaware of the bridge’s existence i.e., whether or not a
bridge is added or deleted from the network, reconfiguration of the
stations is unnecessary. These bridges make use of two processes i.e.,
bridge forwarding and bridge learning.
Source Routing Bridges: - In these bridges, routing operation is
performed by source station and the frame specifies which route to
follow. The host can discover frame by sending a special frame called
discovery frame, which spreads through the entire network using all
possible paths to destination.
Routers – A router is a device like a switch that routes data packets based on
their IP addresses. Router is mainly a Network Layer device. Routers normally
connect LANs and WANs together and have a dynamically updating routing
table based on which they make decisions on routing the data packets. Router
divide broadcast domains of hosts connected through it.
ASSIGNMENT 3:
Twisted Pair Cable:
Wires are twisted together in pairs. Each pair would consist of wire used for
the positive data signal and a wire used for the negative data signal. Any noise
that appears on positive/negative wire of the pair would occur on the other
wire. Because the wires are opposite polarities, these are 180 degrees out of
phase (180 degree or definition of opposite polarities). When the noise appears
on the both wires, it cancels or nulls itself out at the receiving used.
There are two types of twisted pair cable –
Shielded Twisted Pair Cable –
Twisted pair cables are most effectively used in system that uses a
balanced line method of transmission. Cables with shield are called
Shielded twisted pair cables and commonly abbreviated STP.
Unshielded Twisted Pair Cable –
Cables without shield are called unshielded twisted pair cables or UTP.
Twisting the wires together results in characteristics impedance for the
cable. UTP cable is used on Ethernet.
2. Co-axial Cable:
Co-axial cable consists of two conductors. The inner conductor is contained
inside the insulator with the other conductor weaves around it providing a
shield. An insulating protective coating called a jacket covers the outer
conductor. The outer shield protects the inner conductor from outside
electrical signals. Distance between the outer conductor and inner conductor
plus the type of material used for insulating the inner conductor determine the
cable properties.
3. Optical Fibre Cable:
Optical fibre consists of thin glass fibre that can carry information at
frequencies in the visible light spectrum. Typical optical fibre consists of a very
narrow strand of glass called the cladding. A typical core diameter is 62.5
microns.
Typically cladding has a diameter of 125 minors. Coating the cladding is a
protective coating consisting of plastic, it is called the jacket. The device
generating the message has it in electromagnetic from (electrical signal). This
has to be converted into light to send it on optical fibre cable.
ASSIGNMENT 4:
IP addresses are displayed as a set of four digits- the default address maybe
192.158.1.38. Each number on the set may range from 0 to 255. Therefore, the
total IP address range ranges from 0.0.0.0 to 255.255.255.255.
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
IP address is basically divided into two parts: X1. X2. X3. X4
1. [X1. X2. X3] is the Network ID
2. [X4] is the Host ID
Network ID–
It is the part of the left-hand IP address that identifies the specific
network where the device is located. In the normal home network,
where the device has an IP address 192.168.1.32, the 192.168.1 part of
the address will be the network ID. It is customary to fill in the last part
that is not zero, so we can say that the device’s network ID is
192.168.1.0.
Hosting ID–
The host ID is part of the IP address that was not taken by the network
ID. Identifies a specific device (in the TCP / IP world, we call devices
“host”) in that network. Continuing with our example of the IP address
192.168.1.32, the host ID will be 32- the unique host ID on the
192.168.1.0 network.
ASSIGNMENT 5:
#include <stdio.h>
#include <conio.h>
#include <string.h>
int calculation(int no)
{
int r,s=0;
while(no>0)
{
r = no%10;
s = s + r;
no = (no-r)/10;
}
return s;
}
void receiverParity(int choice)
{
int s,no;
printf("Enter Received Codeword : ");
scanf("%d",&no);
printf("\n");
s = calculation(no);
if(s%2==0 && choice==1 || s%2!=0 && choice==2)
printf("No error Occurred");
else
printf("Error Occurred");
}
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
void senderParity(int no)
{
int choice,s,codeword;
printf("1:Even Parity\n2: Odd Parity\n");
printf("\n");
printf("Enter Your Choice : ");
scanf("%d",&choice);
printf("\n");
s = calculation(no);
switch(choice)
{
case 1:
{
if(s%2!=0)
codeword = (no*10)+1;
else
codeword = no*10;
break;
}
case 2:
{
if(s%2!=0)
codeword = no*10;
else
codeword = (no*10)+1;
break;
}
default:
printf("Wrong Choice");
break;
}
printf("Codeword : %d\n\n",codeword);
receiverParity(choice);
}
int main()
{
printf("Simple Parity Checking\n");
printf("********************\n\n");
int no;
printf("Enter Binary Number : ");
scanf("%d",&no);
printf("\n");
senderParity(no);
}
OUTPUT:
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
ASSIGNMENT 6:
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Matrix Parity Checking\n");
printf("********\n\n");
int row,col;
printf("Enter Number of Rows : ");
scanf("%d",&row);
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
printf("Enter Number of Column : ");
scanf("%d",&col);
printf("\n");
int arr[100][100];
int i,j;
for(i=0;i<row;i=i+1)
{
for(j=0;j<col;j=j+1)
{
printf("arr[%d][%d] : ",i,j);
scanf("%d",&arr[i][j]);
}
printf("\n");
}
printf("Entered Matrix\n");
printf("******\n\n");
for(i=0;i<row;i=i+1)
{
for(j=0;j<col;j=j+1)
{
printf("%d\t",arr[i][j]);
}
printf("\n");
}
int choice,s;
printf("\n");
printf("1: Even Parity\n2: Odd Parity\n\n");
printf("Enter Your Choice : ");
scanf("%d",&choice);
printf("\n");
sender(arr,choice,row,col);
}
OUTPUT:
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
ASSIGNMENT 7:
#include <iostream>
#include <sstream>
#include<bits/stdc++.h>
using namespace std;
int i;
string divisor1="";
for(i=1;i<=pick;i++)
{
divisor1 = divisor1 + "0";
}
pick += 1;
}
if (tmp[0] == '1')
tmp = XOR(divisor, tmp) + dividend[pick];
else
tmp = XOR(divisor1, tmp) + dividend[pick];
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
return tmp;
}
void receiver(string key)
{
string r,tmp;
cout<<endl;
cout<<"Enter Receiver Side Codeword : ";
cin>>r;
cout<<endl;
tmp = calculation(r,key);
stringstream geek(tmp);
int x = 0;
geek >> x;
if(x == 0)
{
cout<<"Correct Codeword";
}
else
{
cout<<"Incorrect Codeword";
}
}
void encodeData(string data, string key)
{
int i,power,noOfZeroes=0;
string c = data;
for(i=0;i<=100;i=i+1)
{
power = pow(2,i);
if(power>=(i+data.length()+1))
{
noOfZeroes = i;
break;
}
}
for(i=1;i<=noOfZeroes;i++)
{
c = c + "0";
}
int main()
{
cout<<"Cyclic Redundancy Check\n";
cout<<"***********************\n\n";
string data;
string key;
encodeData(data, key);
receiver(key);
return 0;
}
OUTPUT:
ASSIGNMENT 8:
#include <iostream>
#include <sstream>
#include<bits/stdc++.h>
using namespace std;
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
string xorCalculate(string a, string b)
{
string result = "";
int n = b.length();
for(int i = 1; i < n; i++)
{
if (a[i] == b[i])
result += "0";
else
result += "1";
}
return result;
}
int getMax(int *p)
{
int max=0,i;
for(i=0;i<5;i++)
{
if(max<*p)
{
max = *p;
}
p = p + 1;
}
return max;
}
string concatBinary(int *p, int c)
{
int i;
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
string j, s="";
for(i=0;i<c;i++)
{
stringstream ss;
ss<<*p;
ss>>j;
s = j + s;
p++;
}
return s;
}
string binaryConvert(int no)
{
int r,a[16],c=0,s=no;
string k;
while(no>0)
{
r = no%2;
a[c]=r;
no = no/2;
c=c+1;
}
k = concatBinary(a,c);
return k;
}
int countBit(string s)
{
int i=0,count=0;
while(s[i]!='\0')
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
{
count = count + 1;
i++;
}
return count;
}
int binaryToDeci(string no)
{
int p=0,s=0,i;
int l = no.length();
for(i=(l-1);i>=0;i--)
{
s = s + (((int)no[i]-48) * pow(2,p));
p = p + 1;
}
return s;
}
int onesComplement(string no)
{
string s="";
int l = no.length();
int i;
for(i=0;i<l;i=i+1)
{
if(no[i]=='0')
{
s = s + "1";
}
else
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
{
s = s + "0";
}
}
int result = binaryToDeci(s);
return result;
}
int main()
{
int n;
cout<<"Enter Number of Digit : ";
cin>>n;
cout<<endl;
int arr[n],max,i,sum=0,count0,count1,count2;
string k0,k1,result;
for(i=0;i<n;i=i+1)
{
cout<<"Enter "<<i+1<<" Number : ";
cin>>arr[i];
sum = sum + arr[i];
}
cout<<endl;
cout<<"Sum : "<<sum<<endl;
arr[n] = 0;
max = getMax(arr);
k0 = binaryConvert(sum);
//cout<<"Binary of "<<sum<<" : "<<k0<<endl;
count0 = countBit(k0);
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
k1 = binaryConvert(max);
//cout<<"Binary of "<<max<<" : "<<k1<<endl;
count1 = countBit(k1);
OUTPUT:
ASSIGNMENT 9:
1. Ping (Packet Internet Groper)
ping command is used to ensure that a computer can communicate to a
specified device over the network. ping command sends Internet Control
Message Protocol (ICMP) Echo Request messages in the form of packets
to the destination computer and waits in order to get the response back.
Once the packets are received by the destined computer, it starts
sending the packets back. This command keeps executing until
it is interrupted.
ping command provides details such as
number of packets transmitted
number of packets received
time taken by the packet to return
ping command in generally used for the following purposes:
measuring the time taken by the packets to return to
determine speed of the connection
to make sure that the network connection between host and
the destined computer can be established
2. nslookup
nslookup command queries the DNS in order to fetch the IP address or
the domain name from DNS records.
3. traceroute
This command is used to get the route of a packet. In other words,
traceroute command is used to determine the path along which a packet
travel. It also returns the number of hops taken by the packet to reach
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
the destination. This command prints to the console, a list of hosts
through which the packet travels in order to the destination.
4. host
host command is used to find domain name associated with the IP
address or find IP address associated with domain name. The returned
IP address is either IPv4 or IPv6.
5. netstat
netstat (Network Statistics) is the command that is used to display
routing table, connection information, the status of ports, etc. This
command works with Linux Network Subsystem. This command
basically displays the content of /proc/net file defined in the Linux file
system.
6. Arp
ARP (Address Resolution Protocol) command is used to display and
modify ARP cache, that contains the mapping of IP address to MAC
address. The system’s TCP/IP stack uses ARP in order to determine MAC
address associated with an IP address.
7. ifconfig
ifconfig (Interface Configuration) is a utility in operating system that is
used to set or display the IP address and netmask of a network interface.
It also provides commands to enable or disable an interface. Many UNIX-
like operating system initializes their network interfaces using ifconfig
at boot time. ifconfig is also used to view the MTU (Maximum
transmission unit).
ASSIGNMENT 10:
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
void func(int sockfd)
{
char buff[MAX];
int n;
for (;;) {
bzero(buff, sizeof(buff));
printf("Enter the string : ");
n = 0;
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
while ((buff[n++] = getchar()) != '\n')
;
write(sockfd, buff, sizeof(buff));
bzero(buff, sizeof(buff));
read(sockfd, buff, sizeof(buff));
printf("From Server : %s", buff);
if ((strncmp(buff, "exit", 4)) == 0) {
printf("Client Exit...\n");
break;
}
}
}
int main()
{
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
Compilation –
Server side:
gcc server.c -o server
./server
Client side:
gcc client.c -o client
./client
Output –
Server side:
Socket successfully created..
Socket successfully binded..
Server listening..
server acccept the client...
From client: hi
To client : hello
From client: exit
To client : exit
Server Exit...
Client side:
Socket successfully created..
connected to the server..
Enter the string : hi
From Server : hello
Enter the string : exit
From Server : exit
Client Exit...
ASSIGNMENT 11:
#include <stdio.h>
#include <netdb.h>
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
int main()
{
int sockfd, connfd, len;
struct sockaddr_in servaddr, cli;
Compilation –
Server side:
gcc server.c -o server
./server
Client side:
gcc client.c -o client
./client
Output –
Server side:
Socket successfully created..
Socket successfully binded..
Server listening..
server acccept the client...
From client: hi
To client : hello
From client: exit
To client : exit
Server Exit...
Client side:
Socket successfully created..
connected to the server..
Enter the string : hi
From Server : hello
Enter the string : exit
From Server : exit
Client Exit...
ASSIGNMENT 12:
#include <stdio.h>
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from client";
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
int n, len;
close(sockfd);
return 0;
}
Output :
$ ./server
Client : Hello from client
Hello message sent.
$ ./client
Hello message sent.
Server : Hello from server
JIS College of Engineering
Department of Computer Science and Engineering
Paper Name: Computer Networks Lab
Paper Code: CS 691