Computer Network
Computer Network
2022-2023
LAB MANUAL
PREPARED BY:
Faculty Name: Mr. Ankush Gupta
Signature:
NIIT, Najibabad
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
LIST OF EXPERIMENTS
8 WAP to run and use services/commands like ping, trace route, nslookup, arp,
telnet, ftp.
9 WAP to implement Remote Procedure Call in C.
Program Name:
Theory Concept:
Caesar cipher is one of the simplest and wisely known symmetric key cipher. It works by
substituting each of the alphabets of the plain text by corresponding alphabets of cipher text using
encryption algorithm and a key.
The decryption algorithm is just opposite of the encryption algorithm.
If P is the set of plain text letters and C is the set of cipher text letters and k is the key value, the
algorithm works
C=(P+k) mod 26
Code:
#include<stdio.h>
#include<conio.h>
Void encrypt()
{
Char str[100];
Int I,k,len;
Print f(“ Enter the plain Text:”);
Scanf(“%s”, str);
Printf(‘/n Enter the key value:”);
Scanf(“d”, &k);
Printf(“/n The encrypted text is:”);
Len=strlen(str);
For(i=0; i<len; i++)
{
If(((int) str[i]>=65) && ((int) str[i]<=90)
{
Printf(“%c”, (c(str[i])-65+k)%26)+65));
}
If(((int) str[i]>=97) && ((int) str[i]<=122)
{
Printf(“%c”, (c(str[i])-97+k)%26)+127));
}
Printf(“/n”);
}
Void main()
{
Encrypt();
}
Output:
Program Name:
Theory Concept:
CRC stands for Cyclic Redundancy Check. It is an error detection method used by data link layer
of OSI models. It detects the accidental changes in raw data with the help of some redundant bits
in it. Blocks of data entering these systems get a short check value attached based on the remainder
of a polynomial division of their contents.
Code:
#include<stdio.h>
#include<conio.h>
Void main()
{
Int i,j, keylen, msglen:
Char input[100], key[30], temp[30], quot[100], rem[30], key1[30];
Printf(“ Enter the data:”);
Scanf(“%s”, input);
Printf(“ Enter the Key:”);
Scanf(“%s”, key);
Keylen=strlen(key);
Msglen=strlen(input);
Strcpy(key1, key);
For(i=0; i<keylen-; 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’;
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(“Quotient is”);
For(i=0; i<=msglen:i++)
{
Printf(“%c”, quot[i]);
}
Printf(“Remainder is:)”);
For(i=0; i<=keylen-1:i++)
{
Printf(“%c”, rem[i]);
}
Printf(“Final data is”);
For(i=0; i<=msglen:i++)
{
Printf(“%c”, input [i]);
}
For(i=0; i<=keylen-1:i++)
{
Printf(“%c”, rem[i]);
}
}
Output:
Enter the data: 10111011
Enter the key: 1001
Quotient is: 1010111
Remainder is: 110
Final data is: 10111011110
Experiment-3
Program Name:
WAP to implement bit and byte stuffing in C.
Theory Concept:
While sending the data over a network, the data link layer of the OSI model divides it into frames
of varying or same sizes. The system needs a mechanism to identify the frame data and header
separately. So the data link layer distinguishes the ending of one frame by the beginning of another
by using bit and byte stuffing technique.
Code:
Byte Stuffing:
#include<stdio.h>
#include<conio.h>
#definf flag ‘*’
# define esc ‘#’
Void main()
{
Int j=1, I;
Char str[50], frame[50];
Printf(“Enter the string:”);
Scanf(“%s”, str);
Frame[0]=flag;
For(i=0; i<strlen(str); i++)
{
If (str[i]==flag || str[i]==esc)
{
Frame[i]=esc;
I++;
}
Frame[i]=str[i];
I++;
}
Frame[i+1]=flag;
Frame[i]=’10’;
Printf(“/n Frame to send: %s”, frame);
}
Bit Stuffing
#include<stdio.h>
#include<conio.h>
Void main()
{
Char a[10];
Int count=0; i=0; j,l, k=0;
Printf(“ Enter the input string”);
Scanf(“%s”, a);
l-strlen(a);
for(i=0; i<l, i++)
{
If (a[i]==’1’)
{
K=I;
Count=0;
While(a[k]==’1’)
{
Count+=1;
K++;
If(count==5);
{
For(j=l+1; j<k; j--)
{
A[j]=a[j-1];
}
A[k]=’0’;
L++;
Break;
}
I=k;
}
}
Printf(“/n The bit stuffed string is: %s”, a);
}
Output:
Byte Stuffing:
Bit Stuffig:
Program Name:
WAP to understand the basics of network simulation tool packet tracer.
Theory Concepts:
The bottom left-hand corner of the Packet Tracer screen displays eight icons that represent device
categories or groups, such as Routers, Switches, or End Devices.
Moving the cursor over the device categories will show the name of the category in the box. To
select a device, first select the device category. Once the device category is selected, the options
within that category appear in the box next to the category listings.
Step 1: Create a logical network diagram with two PCs and a hub
b) Select Hubs from the options in the bottom left-hand corner. Add a hub to the prototype network
by dragging and dropping a generic hub onto the design area.
c) Select Connections from the bottom left-hand corner. Choose a Copper Straight-through
cable type. Click the first host, PC0, and assign the cable to the Fast Ethernet connector. Click
the hub, Hub0, and select a connection port, Port 0, to connect to PC0.
d) Repeat Step c for the second PC, PC1, to connect the PC to Port 1 on the hub.
*There should be green dots at both ends of each cable connection. If not, check the cable
type selected.
b) From the PC0 window, select the Config tab. Change the PC Display Name to PC-A. (An error
message window will appear warning that changing the device name may affect scoring of the
activity. Ignore this error message.) Select the FastEthernet tab on the left and add the IP address
of 192.168.1.1 and subnet mask of 255.255.255.0. Close the PC-A configuration window by
selecting the x in the upper righthand corner.
c) Click PC1.
d) Select the Config tab. Change the PC Display Name to PC-B. Select the Fast Ethernet tab on
the left and add the IP address of 192.168.1.2 and subnet mask of 255.255.255.0. Close the PC-B
configuration window.
Step 3: Observe the flow of data from PC-A to PC-B by creating network traffic
a) Switch to Simulation mode by selecting the tab that is partially hidden behind the Realtime tab
in the bottom right-hand corner. The tab has the icon of a stopwatch on it.
b) Click the Edit Filters button in the Edit List Filters area. Clicking the Edit Filters button will
create a pop-up window. In the pop-up window, click the Show All/None box to deselect every
filter. Select just the ARP and ICMP filters.
c) Select a Simple PDU by clicking the closed envelope on the right vertical toolbar. Move your
cursor to the display area of your screen. Click PC-A to establish the source. Move your cursor to
PC-B and click to establish the destination.
**Notice that two envelopes are now positioned beside PC-A. One envelope is ICMP, while the
other is ARP. The Event List in the Simulation Panel will identify exactly which envelope
represents ICMP and which represents ARP.
d) Select Auto Capture / Play from the Play Controls area of the Simulation Panel. Below the
Auto Capture / Play button is a horizontal bar, with a vertical button that controls the speed of
the simulation. Dragging the button to the right will speed up the simulation, while dragging is to
the left will slow down the simulation.
e) The animation will run until the message window No More Events appears. All requested events
have been completed. Select OK to close the message box.
f) Choose the Reset Simulation button in the Simulation Panel. Notice that the ARP envelope is
no longer present. This has reset the simulation but has not cleared any configuration changes or
dynamic table entries, such as ARP table entries. The ARP request is not necessary to complete
the ping command because PC-A already has the MAC address in the ARP table.
g) Choose the Capture / Forward button. The ICMP envelope will move from the source to the
hub and stop. The Capture / Forward button allows you to run the simulation one step at a time.
Continue selecting the Capture / Forward button until you complete the event.
h) Choose the Power Cycle Devices button on the bottom left, above the device icons.
i) An error message will appear asking you to confirm reset. Choose Yes. Now both the ICMP and
ARP envelops are present again. The Reset Network button will clear any configuration changes
not saved and will clear all dynamic table entries, such as the ARP and MAC table entries.
Step 4: View ARP Tables on each PC
a) Choose the Auto Capture / Play button to repopulate the ARP table on the PCs. Click OK
when the No More Events message appears.
c) Click PC-A. The ARP table for PC-A will appear. Notice that PC-A does have an ARP entry
for PC-C. View the ARP tables for PC-B and PC-C as well. Close all ARP table windows.
d) Click the Select Tool on the right vertical tool bar. (This is the first icon present in the toolbar.)
f) Select the Command Prompt and type the command arp -a and press enter to view the ARP
table from the desktop view. Close the PC-A configuration window.
i) Click the Check Results button at the bottom of the instruction window to verify that the
topology is correct.
Output:
Experiment- 5
Program Name:
Theory Concepts:
A client has requested that you set up a simple network with two PCs connected to a switch. Verify
that the hardware, along with the given configurations, meet the requirements of the client.
b) Using straight-through cables, connect PC0 to interface Fa0/1 on Switch0 and PC1 to interface
Fa0/2 on Switch0.
c) Configure PC0 using the Config tab in the PC0 configuration window:
1. IP address: 192.168.10.10
2. Subnet Mask 255.255.255.0
d) Configure PC1 using the Config tab in the PC1 configuration window:
1. IP address: 192.168.10.11
2. Subnet Mask 255.255.255.0
1. Click PC0.
2. Choose the Desktop tab.
3. Choose Command Prompt.
4. Type: ping 192.168.10.11 and press enter.
b) A successful ping indicates the network was configured correctly and the prototype validates
the hardware and software configurations. A successful ping should resemble the below output:
PC>ping 192.168.10.11
Pinging 192.168.10.11 with 32 bytes of data:
Reply from 192.168.10.11: bytes=32 time=170ms TTL=128
Reply from 192.168.10.11: bytes=32 time=71ms TTL=128
Reply from 192.168.10.11: bytes=32 time=70ms TTL=128
Reply from 192.168.10.11: bytes=32 time=68ms TTL=128
Ping statistics for 192.168.10.11:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 68ms, Maximum = 170ms, Average = 94ms
c) Click the Check Results button at the bottom of the instruction window to check your work.
Output:
Experiment- 6
Program Name:
Theory Concepts:
A network administrator wants to provide static routes between the available networks to create
internetworking. These routes are statically fed into the routing table of the router in the offline
mode by the network administrator.
Steps:
Program Name:
WAP to learn handling and configuration of networking hardware (cables).
Theory Concept:
A network administrator wants to subnet the available network so as to create modularity in the
network. Given a simple network, the administrator can divide this address into various subnets
depending upon the requirement.
Steps:
1. Cut the cable to the length needed.
2. Strip back the cable jacket approximately 1 inch.
Use the cutter provided with the crimping tool or strip by hand.
Be careful not to nick the individual wires.
Un-twist each of the 4 pairs and straighten each wire as much as possible between the
fingers.
3. Use the 568-B wiring scheme on both ends for a standard patch cable.
For a crossover type cable use the 568-B scheme on one end and the 568A on the other end.
8. Repeat the process on the other end using the desired wiring scheme.
9. Always use a cable tester to check for continuity, opens and shorts.
Experiment- 8
Program Name:
WAP to run and use services/commands like ping, trace route, ping, arp, ipconfig, netstat etc.
Theory Concepts:
1. Ping
Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message
Protocol (ICMP) Echo Request messages. The receipt of corresponding Echo Reply messages are
displayed, along with round-trip times. Ping is the primary TCP/IP command used to troubleshoot
connectivity, reachability, and name resolution. You can use ping to test both the computer name
and the IP address of the computer.
3. Arp
Displays and modifies entries in the Address Resolution Protocol (ARP) cache, which contains
one or more tables that are used to store IP addresses and their resolved Ethernet or Token Ring
physical addresses. There is a separate table for each Ethernet or Token Ring network adapter
installed on your computer.
4. TRACERT
If someone would like to know how he goes from his house to his office he could just tell the list
of the crossroads where he passes. The same way we can ask the data sent over from your computer
to the web server which way does it go, through which devices? We ask it by using the utility
called traceroute. In most computers today you can use this tool from the command line: In UNIX
machines it is called traceroute, in MS Windows machines it is called tracert.
5. NETSTAT Command
This command is used to get information about the open connections on your system (ports,
protocols being used, etc.), incoming and outgoing data and also the ports of remote systems to
which you are connected.
Experiment- 9
Program Name:
Theory Concepts:
Remote Procedure Call (RPC) is a protocol that one program can use to request a service from a
program located in another computer on a network without having to understand the network's
details. Aprocedure call is also sometimes known as a functioncall or a subroutine call. RPC uses
the client-server model.
Code:
#include"rpc/rpc.h"
#include"square.h"
#include"stdio.h"
#include"stdlib.h"
#include"math.h"
cl=clnt_create(argv[1],SQUARE_PROG,SQUARE_VERS,"tcp");
in.arg1=atol(argv[2]);
if(cl==NULL)
{
printf("\nerror:%s",strerror(errno));
exit(-1);
}
if((outp=squareproc_1(&in,cl))==NULL)
{
printf("\nerror :%s",clnt_sperror(cl,argv[1]));
exit(-1);
}
// .h FILENAME: square.h
struct square_in
{
/*input arg*/
long arg1;
};
struct square_out
{
/*op result*/
long res1;
};
program SQUARE_PROG
{
version SQUARE_VERS
{
square_out SQUAREPROC(square_in)=1; /*proc no=1*/
}=1; /*version no*/
}=0x31230000;/*prog no*/
OUTPUT
[root@localhost~]#rpcgen -C square.x
[root@localhost~]#cc -c client.c -o client.o
[root@localhost~]#cc -c square_clnt.c -o square_clnt.o
[root@localhost~]#cc -c square_xdr.c -o square.xdr.o
[root@localhost~]#cc -o client client.o square_clnt.o square_xdr.o
[root@localhost~]#cc -c client.c server.c square_xdr.c
[root@localhost~]#cc -c server.c -o server.o
[root@localhost~]#cc -c square_svc.c -o square_svc.o
[root@localhost~]#cc -o server server.o square_svc.o square_xdr.o
[root@localhost~]#./server &
[1] 2264
[root@localhost~]#./client localhost 4
result is: 16
Experiment-10
Program Name:
WAP to implement socket programming in C.
Theory Concepts:
Socket programming is a way of connecting two nodes on a network to communicate with each
other. One socket(node) listens on a particular port at an IP, while other socket reaches out to the
other to form a connection. Server forms the listener socket while client reaches out to the server.
Code:
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#define PORT 8080
int main(int argc, char const *argv[])
{
int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
char buffer[1024] = {0};
char *hello = "Hello from server";
Output: