CN Lab Manual Format EDITED

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 32

1

EX NO: 1 IMPLEMENTATION OF NETWORKING COMMANDS


AIM:
To study the basic networking commands such as tcpdump, netstat, ipconfig, nslookup
and traceroute.

SOFTWARE REQUIREMENTS:
Command prompt in WINDOWS 10

NETWORKING COMMANDS:
1. C:\>tcpdump: TCPDUMP for Windows is a clone of TCPDUMP, the most used network
sniffer/analyzer for UNIX, compiled with the original tcpdump code (tcpdump.org), and our
own packet capture technology Microlap Packet Sniffer SDK (no libpcap/WinPcap/npcap).
2. C:\>netstat: The netsat displays a variety of statistics about a computers active TCP/IP
connections. This tool is most useful when you are having trouble with TCP/IP application such
as HTTP and FTP.

OUTPUT:

3. C:\>ipconfig: The ipconfig command displays information about the host (the computer
your sitting at) computer TCP/IP configuration
(1)C:\>ipconfig/all: This command displays detailed configuration information bout
your TCP/IP connection including router ,gateway ,DNS ,DHCP and type of Ethernet
adapter in your system.

(2)C:\>ipconfig/renew: Using this command will renew all your IP addresses that
you are currently borrowing from the DHCP server.
2

OUTPUT:

4. C:\>nslookup: The nslookup is used for diagonosing DNS problem. If you can access a
resource by specification an IP address but not it’s DNS , you have a DNS problem.

OUTPUT:

5. C:\>tracert: The tracert command displays a list of all the routers that a packet has to go
through to get from the computers on the internet.
3

OUTPUT:

RESULT:
Thus the networking commands such as tcpdump, netstat, ipconfig, nslookup and
traceroute has been executed in command prompt successfully.

EX NO: 2 IMPLEMENTATION OF HTTP WEB CLIENT


PROGRAM USING TCP SOCKETS.
4

AIM:
To write a HTTP web client program to download a web page using TCP sockets.

ALGORITHM:
1. Start the program
2. Import the socket modeule
3. Define the Host address and the port to be connected
4. Make a socket by binding Host and port with "connect" function
5. Request the client with the "sendall" function
6. Recieve the packets with recv and define it to a response variable
7. Decode the response
8. Print the response
9. Close the socket and end the program

PROGRAM:
import socket
target_website = "www.msec.edu.in"
tcp_port = 80
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_socket.connect((target_website, tcp_port))
http_request = "GET / HTTP/1.1\r\nHost: " + target_website + "\r\n\r\n"
tcp_socket.sendall(http_request.encode())
http_response = b''
while True:
data = tcp_socket.recv(4096)
if not data:
break
http_response += data
result = str(http_response.decode())
print(result)
tcp_socket.close()

OUTPUT:
5

RESULT:
Thus the HTTP Web Client program to download the web page has been implemented
successfully.
6
7

7. Convert the message into a string


8. Print the message
9. End the program when the connection is lost (or if the loop ends if it is started with
one)
10. Stop the program
PROGRAM:
SENDER:
import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind(('localhost', 8080))

print('Chat started.....')

server.listen(10)

client, client_addr = server.accept()

print(f'[+] {client_addr} Client connected to the server')

while True:

command = input('Enter text : ')

command = command.encode()

client.send(command)

print('[+] Text sent')

RECIEVER:
import socket
import subprocess

server_ip ='localhost'
port = 8080
bd = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
bd.connect((server_ip, port))
command = "open"
while command != "close":
command = bd.recv(1024)
print("Recieved >>> ",str(command))
8

OUTPUT:

SENDER:

RECIEVER:
9

RESULT:
Thus the Echo Client and Echo Server using TCP Sockets has been implemented
successfully.
10
11

MODEL WINDOW DIAGRAM FOR L-SIM

N-S IM Network simulation software:

It is developed to provide basic understanding and implementation of various advanced concepts in


networking. The software provides an opportunity to understand network fundamentals through animations
& simulations.
The simulation provides for network experimentation with various LAN and WAN protocols,
network devices, routers, encryption, decryption, file transfer, error insertion and analysis of error rate and
throughput etc.
12

MODEL WINDOW DIAGRAM FOR N-SIM

Rapid advances in computer & communication technologies have resulted in the increasing merger
of these two fields. The lines have blurred among computing, switching & digital transmission equipment;
and the same digital techniques are being used for data, audio & video transmission. The intgrated systems
are broadly divided as follows

- DATA COMMUNICATION dealing with transmission, transmission media, signal decoding,


interfacing, data link control & multiplexing.

- NETWORKING deals with the technology & architecture of communication network.

- COMMUNICATION PROTOCOLS which covers the architecture as well.

Data transfer using serial and parallel ports, Ethernet and wireless LAN with complete protocol
understanding and actual hands on with hardware & software with ease.
Network laboratory consists of DCT-03 Data communication trainer kit, LTS- 01 LAN / Wireless LAN
training system, L-SIM LAN / WLAN protocol simulator and analyzer software & N-SIM Network
simulation software.
Data communication is a term referred when the sender and receiver are digital devices, which
communicate with each other by means of binary information. The objective of this trainer kit is to clear
the various aspects of the data communications which comprise of

 The information source or sender.


 The medium for carrying information.
 The information receiver.
 The communication protocols, which ensure proper transfer of data.

RESULT:
Thus the study of network simulator (ns) and simulation of congestion control algorithms using ns
is executed and verified.
13

EX NO: 5 CAPTURING AND EXAMINING THE PACKETS USING


WIRESHARK TOOL

AIM:

To capture and examine the packets using wireshark tool


OBJECTIVES:
 Using Wireshark tool to monitor the packet flow
PROCEDURE:
Step 1: Start Wireshark. Double-click the Wireshark icon, which is located on the desktop.
Step 2: Select an interface to use for capturing packets. From the Capture menu, choose
Interfaces.

Step 3: Start a network capture.


a. Choose the local network Ethernet interface adapter for capturing network traffic.
Click the Start button of the chosen interface.
b. Write down the IP address associated with the selected Ethernet adapter, because that
is the source IP address to look for when examining captured packets.
14

Generate and Analyze Captured Packets

Step 1: Open a browser and access a website.


a. Go to www.google.com. Minimize the Google window, and return to Wireshark.
You should see captured traffic similar to that shown below.

Note: Your instructor may provide you with a different website. If so, enter the
website name or address here:
b. The capture windows are now active. Locate the Source, Destination, and Protocol
columns on the Wireshark display screen. The HTTP data that carries web page text
and graphics uses TCP for reliability.

Step 2: Stop the capture. From the Wireshark Capture menu, choose Stop.
15

Step 3: Analyze the captured output.

RESULT:

Thus the packet examining and capturing has been completed using the wireshark tool
successfully.
16

EX NO: 6 STUDY OF TCP/UDP PERFORMANCE USING NS 2

AIM:
To Study of TCP/UDP performance using Simulation tool.

TOOLS USED:
Opnet Simulator

INTRODUCTION:
The transport layer protocols provide connection- oriented sessions and
reliable data delivery services. This paper seeks to reflect a comparative analysis
between the two transport layer protocols, which are TCP/IP and UDP/IP, as well to
observe the effect of using these two protocols in a client server network.
The transport layer is not just another layer. It is the heart of the whole
protocol hierarchy. Its task is to provide reliable, cost-effective data transport from
the source machine to the destinationmachine, independently of the physical network
or networks currently in use.
TCP and UDP are transport layer components that provide the connection
point through which applications access network services. TCP and UDP use IP,
which is a lower-layer best effort delivery service.

The ultimate goal of the transport layer is to provide efficient, reliable, and
cost-effective service to its users, normally processes in the application layer. To
achieve this goal, the transport layer makes use of the services provided by the
network layer.

The Transport layer meets a number of functions:


 enabling the applications to communicate over the network at the same time
when using a single device;
 ensure that all amount of data is receive by the correct application;6
 responsible for fragmentation and reassembly;
 develop mechanism for handling errors.
Comparison Between TCP And UDP

Service TCP UDP


Guaranteed Returns acknowledgments. UDP does not return ACKs
message delivery
Congestion Network devices can take advantage If ACK, are missing, the network
controls of TCP ACK to control the cannot signal congestion to the
behavior of sender. sender.
17
18

TCP TCP

UDP UDP

Traffic/Link utilization from the WAN to the server

TCP

UDP

Link utilization with a 0.5% packets discard ratio

The main difference between these two protocols is that TCP provides reliability and
congestion control services, while UDP is orientated to improve performance.
The most important and common thing that TCP and UDP are using is the ability to set
a host-to-host communication channel, so the packets will be delivered between processes
running on two different computers.

RESULT:
Thus the TCP/UDP performance has been simulated successfully using OPNET.
19

EX NO: 7 IMPLEMENTATION OF UDP TRANSMISSION.

BRIEF:

 User Datagram Protocol (UDP) is a transport layer protocol used for


communication over IP networks.
 UDP is a connectionless protocol, meaning that it does not establish a
dedicated end-to-end connection between sender and receiver before
transmitting data.
 UDP provides a minimalistic approach to data transmission, with no error
checking or reliability mechanisms built into the protocol.
 UDP is often used for applications that prioritize speed and efficiency over
reliability, such as online gaming, streaming media, and real-time
communication.
 UDP is distinguished from the Transmission Control Protocol (TCP), another
commonly used transport layer protocol, which provides more reliable data
transmission through mechanisms like flow control, congestion avoidance,
and error recovery.

USE CASE:

1. Real-time applications: UDP is commonly used in real-time applications that


require low latency, such as online gaming, voice over IP (VoIP), video
conferencing.

2. Broadcast and multicast: UDP is well-suited for broadcasting and


multicasting data to multiple recipients at once.

3. DNS: UDP is used for Domain Name System (DNS) queries, which convert
domain names into IP addresses.
20

4. IoT devices: UDP can be used to send small packets of data between devices,
such as sensor readings or control messages.

5. Network management: UDP is also used in network management


applications, such as Simple Network Management Protocol (SNMP) and
Trivial File Transfer Protocol (TFTP), which are used for monitoring and
managing network devices.

AIM:

To implement ‘UDP’ transmission using python.

ALGORITHM:

TRANSMITTER:

1. Start the program.


2. Define the DESTINATION and the PORT.
3. Create a socket for establishing a ‘UDP’ transmission.
4. Prompt the user for a message that is to be transmitted.
5. Encode the message and send it to the other party by setting the port and the
destination IP.
6. End the program by closing the socket.
RECIEVER:
1. Start the program.
2. Define the IP and the PORT to listen on.
3. Create a socket for establishing a ‘UDP’ transmission.
4. Bind the IP and the port.
5. Receive the message and print it.
6. End the program.
21

CODE (TRANSMITTER):

import socket

UDP_IP = "localhost" # IP address of the destination host

UDP_PORT = 8080 # Port number to use

# Create a socket object for UDP communication

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

print("\n////UDP COMMUNICATION STARTED\\\\\\\\")

message = str(input("\nEnter the message : "))

sock.sendto(message.encode(), (UDP_IP, UDP_PORT))

sock.close()

CODE (RECEIVER):

import socket

UDP_IP = "localhost" # IP address to listen on

UDP_PORT = 8080 # Port number to listen on

# Create a socket object for UDP communication

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

sock.bind((UDP_IP, UDP_PORT))

print("\nWaiting for message...\n")

while True:

data, addr = sock.recvfrom(1024) # 1024 is the buffer size

print("Received message >>>", data.decode())

print("From address:", addr)


22

OUTPUT:

TRANSMITTER:

RECEIVER:

RESULT:

Thus the ‘UDP’ transmission has been implemented successfully.


23

EX NO:8 SIMULATION OF ARP PROTOCOL.


AIM:

To implement ‘ARP’ protocol using python script.

ALGORITHM:

1. Start the program


2. Import the ‘OS’ module
3. Define the destination ‘IP’ for the ARP signal.
4. Obtain the desired number of attempts at ARP from the user as x.
5. Check if the ‘IP’ is reachable or not by pinging it.
6. If the ‘IP’ is reachable proceed to step 7 if not Terminate the
program.
7. Send an ARP signal with the IP as a broadcast.
8. If the ARP reply is received, print that the ARP was successfully
communicated and found the device. If not proceed with step 9.
9. Send ARP requests x times.
10. If found follow step 9 else ask the user to display the arp cache
table and display it if they want to.

PROGRAM:

import os

import subprocess

dst_ip = str(input("\nEnter the destination IP: "))

x = int(input("Enter the desired attempts for arp: "))

def ping(host):

print("\nPING_ING {host}\n---------------------")
24

output = subprocess.Popen(['ping', '-n', '1', '-w', '1000', host],


stdout=subprocess.PIPE).communicate()[0]

print(f"Result:\n{output}\n----------------------")

if b'Reply from ' in output:

return True

else:

return False

def Arp_checker(v,w0):

w = w0

a = w0

if v == 0:

print("ARP was successfully communicated and found the device.")

else:

print("ARP was successfully communicated but couldn't find the


device..")

print("\nTrying again...\n--------")

if w!=0:

n1 = os.system(f"arp -s '{dst_ip}'")

Arp_checker(n1,w-1)

else:

w0 = w0

print(f"Couldn't recieve a reply from the device after the desired


attempts.")

q = input("\nDo you wish to see the ARP cache(y/n): ")

if q == "y":
25

with os.popen('arp -a') as f:

data = f.read()

print(data)

else:

print("Program ends...")

if ping(dst_ip):

print('Host is reachable.')

else:

print('Host is not reachable.')

break

print(f"\nARP-ING: {dst_ip}\n")

n = os.system(f"arping -c 1 '{dst_ip}'")

Arp_checker(n,x)
26

OUTPUT:

RESULT:

Thus the ARP protocol has been implemented successfully.

EX NO 9 STIMULATION OF DISTANCE VECTOR ROUTING


AIM:
27

To stimulate and study the link state routing algorithm using simulation using NS2.

ALGORITHM:

o The Distance vector algorithm is iterative, asynchronous and distributed.

 Distributed: It is distributed in that each node receives information from one or


more of its directly attached neighbors, performs calculation and then distributes
the result back to its neighbors.
 Iterative: It is iterative in that its process continues until no more information is
available to be exchanged between neighbors.
 Asynchronous: It does not require that all of its nodes operate in the lock step with
each other.

o The Distance vector algorithm is a dynamic algorithm.


o It is mainly used in ARPANET, and RIP.
o Each router maintains a distance table known as Vector.

PROGRAM:
#include<stdio.h>
#include<iostream>
using namespace std;

//ducslectures.blogspot.in
struct node
{
unsigned dist[6];
unsigned from[6];
}DVR[10];
int main()
{
cout<<"\n\n PROGRAM TO IMPLEMENT DISTANCE VECTOR ROUTING ALGORITHM ";
int costmat[6][6];
int nodes, i, j, k;
cout<<"\n\n Enter the number of nodes : ";
cin>>nodes; //Enter the nodes
cout<<"\n Enter the cost matrix : \n" ;
for(i = 0; i < nodes; i++)
{
for(j = 0; j < nodes; j++)
28

cin>>costmat[i][j];
costmat[i][i] = 0;
DVR[i].dist[j] = costmat[i][j]; //initialise the distance equal to cost matrix
DVR[i].from[j] = j;
}
}
for(i = 0; i < nodes; i++) //We choose arbitary vertex k and we calculate the
//direct distance from the node i to k using the cost matrix and add the distance from k to node
j
for(j = i+1; j < nodes; j++)
for(k = 0; k < nodes; k++)
if(DVR[i].dist[j] > costmat[i][k] + DVR[k].dist[j])
{ //We calculate the minimum distance
DVR[i].dist[j] = DVR[i].dist[k] + DVR[k].dist[j];
DVR[j].dist[i] = DVR[i].dist[j];
DVR[i].from[j] = k;
DVR[j].from[i] = k;
//ducslectures.blogspot.in
}
for(i = 0; i < nodes; i++)
{
cout<<"\n\n For router: "<<i+1;
for(j = 0; j < nodes; j++)
cout<<"\t\n node "<<j+1<<" via "<<DVR[i].from[j]+1<<" Distance "<<DVR[i].dist[j];
}
cout<<" \n\n ";
return 0;
}

OUTPUT:
29

RESULT:

Thus the Distance Vector Routing has been implemented successfully.

EX NO 10 IMPLEMENTATION OF CLIENT SERVER CHAT


30

AIM:

To implement Client Server chat using python.

ALGORITHM:

CHAT PARTY:

1. Start the program.


2. Define the HOST and the PORT.
3. Start Listening for connection.
4. When a connection is establishes display the message as ‘connection
established’.
5. After connecting, prompt a message to input text.
6. Encode the message and send it to the other party.
7. Wait for the other party to send their message.
8. End the program when the connection is lost.

PROGRAM (SPEAKER 1):

import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 8080))
server.listen(1)
print('Chat started.....')
client, client_addr = server.accept()
print(f'[+] {client_addr} Client connected to the server')
while True:
command = input('Enter text : ')
command = command.encode()
client.send(command)
print('[+] Text sent')
31

message = client.recv(1024)
print("\nReceived >>>", message.decode())
CODE (SPEAKER 2):

import socket
server_ip = 'localhost'
port = 808
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((server_ip, port)
while True:
response = client.recv(1024)
print("\nReceived >>>", response.decode())
message = input('Enter text : ')
message = message.encode()
client.send(message)
print('[+] Message sent')

OUTPUT:
32

SPEAKER 1:

SPEAKER 2:

RESULT:

Thus the implementation of Client Server chat has been implemented


successfully.

You might also like