0% found this document useful (0 votes)
13 views

Computer Network

Uploaded by

Khushi Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Computer Network

Uploaded by

Khushi Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

NIIT , Najibabad

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

2022-2023

LAB MANUAL

COURSE : B.Tech (CSE)


SEMESTER : VI
SUBJECT : Computer Network LAB
SUBJECT CODE : RCS-651

PREPARED BY:
Faculty Name: Mr. Ankush Gupta
Signature:
NIIT, Najibabad
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
LIST OF EXPERIMENTS

COURSE: B.Tech SEMESTER: VI SESSION: 2018-19


BRANCH: CSE
SUBJECT CODE & NAME: KCS-663, Computer Network Lab

SI No. NAME OF EXPERIMENTS


1 WAP to implement Caeser Cipher for encryption and decryption in C

2 WAP to implement CRC in C.

3 WAP to implement bit and byte stuffing in C.

4 WAP to understand the basics of network simulation tool packet tracer.

5 WAP to simulate the configuration of hub and switch in Packet tracer

6 WAP to simulate static routing for internetworking using packet tracer.

7 WAP to learn handling and configuration of networking hardware.

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.

10 WAP to implement socket programming in C.


Experiment-1

Program Name:

WAP to implement Caeser Cipher for encryption and decryption in C.

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:

Enter the plain Text: HELLO


Enter the key value: 3
The encrypted text is: KHOOR
Experiment-2

Program Name:

WAP to implement CRC in C

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:

Enter the string: abc*bcd#ef


Frame to be sent is: *abc#*bcd##ef*

Bit Stuffig:

Enter the input string: 001111110011


The bit stuffed string is: 01111110001111101001101111110
Experiment-4

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

Select the device option that is required.


a) Select End Devices from the options in the bottom left-hand corner. Drag and drop two generic
PCs onto your design area.

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.

Step 2: Configure host names and IP addresses on the PCs

a) Click PC0. A PC0 window will appear.

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.

b) Select the magnifying glass on the right vertical tool bar.

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

e) Click PC-A and select the Desktop tab.

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.

g) Examine the ARP table for PC-B.

h) Close the PC-B 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:

WAP to simulate the configuration of hub and switch in Packet tracer

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.

Step 1: Set up the network topology

a) Add two PCs and a Cisco 2950T switch.

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

Step 2: Test connectivity from PC0 to PC1

a) Use the ping command to test connectivity.

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

Close the configuration window.

c) Click the Check Results button at the bottom of the instruction window to check your work.

Output:
Experiment- 6

Program Name:

WAP to simulate static routing for internetworking using packet tracer.

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:

1. Take 2 routers and 2 switches


2. Connect the switches to routers using the copper straight through cables.
3. Connect two PCs to each switch using copper straight through cables. Rename the PCs so that
they can be easily identified.
4. Configure Router0.
Click on the config tab of router.
Select the interface that you want to configure ( the interface through which the router is
connected to the switch)
Assign an IP address to that interface, this is the address of the local network
192.168.1.33 along with the subnet mask 255.255.255.224.
Switch the port status to ON.
Configure the other routers likewise.
5. Configure the PC.
Click on the config tab of the PC.
Select the interface through which it is connected to the switch.
Assign IP address to that interface.
Make sure that the IP address is of the same as the router has for this interface. Add the
address of the router as the default gateway of this PC.
Configure the other PCs likewise.
6. Connect the routers using the fiber optic cable.
7. Internetwork the routers
Set the static ip route using the command ip route 192.168.1.65 255.255.255.224.
This will create a static route for the traffic coming from the network N1 to the network
N2.
Configure the other router interfaces likewise.
Output:
Experiment- 7

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.

4. Bring all of the wires together as closely as possible.


Hold the grouped (and sorted) wires together tightly between the thumb, and the forefinger.
Cut all of the wires at a perfect 90 degree angle from the cable, 1/2 inch from the end of the
cable jacket.

Use a sharp cutting tool so as not to "squash" the wire ends.


5. With the connector pins facing up, carefully insert the wires into the connector.
Apply a moderate amount of force in order to properly seat the wires against the contacts in
the connector.
6. Observe the tip of the connector to confirm that all the wires are fully inserted.
The end of each wire you should be in full view.
There should be enough of the cable jacket inside the connector to crimp against.
7. Place the connector into the crimp tool, and squeeze hard so that the handle reaches its full
swing.

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.

To test a TCP/IP configuration by using the ping command:


• To quickly obtain the TCP/IP configuration of a computer, open Command Prompt, and
then type ipconfig . From the display of the ipconfig command, ensure that the network
adapter for the TCP/IP configuration you are testing is not in a Media disconnected state.
• At the command prompt, ping the loopback address by typing ping 127.0.0.1
• Ping the IP address of the computer.
• Ping the IP address of the default gateway. If the ping command fails, verify that the default
gateway IP address is correct and that the gateway (router) is operational.
• Ping the IP address of a remote host (a host that is on a different subnet). If the ping
command fails, verify that the remote host IP address is correct, that the remote host is
operational, and that all of the gateways (routers) between this computer and the remote
host are operational.
• Ping the IP address of the DNS server. If the ping command fails, verify that the DNS
server IP address is correct, that the DNS server is operational, and that all of the gateways
(routers) between this computer and the DNS server are operational.
2. Ipconfig
Displays all current TCP/IP network configuration values and refreshes Dynamic Host
Configuration Protocol (DHCP) and Domain Name System (DNS) settings. This command is most
useful on computers that are configured to obtain an IP address automatically. This enables users
to determine which TCP/IP configuration values have been configured by DHCP, Automatic
Private IP Addressing (APIPA), or an alternate configuration.
• If the Adapter name contains any spaces, use quotation marks around the adapter name
(that is, "Adapter Name").
• For adapter names, ipconfig supports the use of the asterisk (*) wildcard character to
specify either adapters with names that begin with a specified string or adapters with names
that contain a specified string.
• For example, Local* matches all adapters that start with the string Local
and *Con* matches all adapters that contain the string Con.

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:

WAP to implement Remote Procedure Call in C.

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:

//SERVER FILENAME: server.c

#include"rpc/rpc.h"
#include"square.h"
#include"stdio.h"
#include"stdlib.h"
#include"math.h"

square_out *squareproc_1_svc(square_in *inp,struct svc_req *rqstp)


{
static square_out out;
out.res1= inp->arg1 * inp->arg1;
return(&out);
}

// CLIENT FILENAME: client.c


#include"errno.h"
#include"rpc/rpc.h"
#include"square.h"
#include"stdio.h"
#include"stdlib.h"
#include"math.h"

int main(int argc,char **argv)


{
CLIENT *cl;
square_in in;
square_out *outp;
f(argc!=3)
{
printf("\n\n error:insufficient arguments!!!");
exit(-1);
}

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);
}

printf("\n\n result is : %ld",outp->res1);


exit(0);
}

// .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";

// Creating socket file descriptor


if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
perror("socket failed");
exit(EXIT_FAILURE);
}

// Forcefully attaching socket to the port 8080


if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT,
&opt, sizeof(opt)))
{
perror("setsockopt");
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons( PORT );

// Forcefully attaching socket to the port 8080


if (bind(server_fd, (struct sockaddr *)&address,
sizeof(address))<0)
{
perror("bind failed");
exit(EXIT_FAILURE);
}
if (listen(server_fd, 3) < 0)
{
perror("listen");
exit(EXIT_FAILURE);
}
if ((new_socket = accept(server_fd, (struct sockaddr *)&address,
(socklen_t*)&addrlen))<0)
{
perror("accept");
exit(EXIT_FAILURE);
}
valread = read( new_socket , buffer, 1024);
printf("%s\n",buffer );
send(new_socket , hello , strlen(hello) , 0 );
printf("Hello message sent\n");
return 0;

Output:

Client:Hello message sent


Hello from server
Server:Hello from client
Hello message sent

You might also like