0% found this document useful (0 votes)
10 views31 pages

CN Lab Manual Working

The document provides an overview of networking hardware and functionalities, detailing components such as servers, clients, peers, and various networking devices like routers, hubs, switches, bridges, repeaters, and gateways. It also discusses software components, including network operating systems and protocol suites, as well as techniques for error detection and correction, such as parity bits and CRC. Additionally, it includes examples of flow control mechanisms and the implementation of distance vector routing algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

CN Lab Manual Working

The document provides an overview of networking hardware and functionalities, detailing components such as servers, clients, peers, and various networking devices like routers, hubs, switches, bridges, repeaters, and gateways. It also discusses software components, including network operating systems and protocol suites, as well as techniques for error detection and correction, such as parity bits and CRC. Additionally, it includes examples of flow control mechanisms and the implementation of distance vector routing algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Ex NO : 1

Aim:- Study of all networking hardware and Functionalities

 What is a Network?
A network consists of two or more computers that are linked in order to share
resources (such as printers and CDs), exchange files, or allow electronic
communications. The computers on a network may be linked through cables,
telephone lines, radio waves, satellites, or infrared light beams.

Networking Components:-
Computer networks components comprise both Hardware
parts as well as the software parts required for installing computer networks, both at
organizations and at home. The hardware components are the server, client, peer,
transmission medium, and connecting devices. The software components are operating
system and protocols.

Diagram: Components of Network.

Hardware Components:-
Servers:−Servers are high-configuration computers that manage the resources of the
network. The network operating system is typically installed in the server and so they
give user accesses to the network resources. Servers can be of various kinds: file
servers, database servers, print servers etc.
Clients: − Clients are computers that request and receive service from the servers to
access and use the network resources.
Peers:- Peers are computers that provide as well as receive services from other peers
in a work group network.
Transmission Media:- Transmission media are the channels through which data is
transferred from one device to another in a network. Transmission media may be
guided media like coaxial cable, fiber optic cables etc; or maybe unguided media like
microwaves, infra-red wave etc.
Networking Devices:- Connecting devices act as middleware between networks or
computers, by binding the network media together. Some of the common connecting
devices are:
1. Routers
2. Hub
3. Switch
4. Bridge
5. Repeater
6. Gateway

 Software Components:-
 Operating System − Network Operating Systems is typically installed in the
server and facilitate workstations in a network to share files, database,
applications, printers etc.
 Protocol Suite − A protocol is a rule or guideline followed by each computer for
data communication. Protocol suite is a set of related protocols that are laid down
for computer networks. The two popular protocol suites are−
 OSI Model ( Open System Interconnections)
 TCP / IP Model.

 LAN Adapter:-
A LAN adapter is an expansion board that is used to connect a computer or computing
device to a network. LAN adapter is the most common and generic alternate name for a
Network Interface Card(NIC). Similar products, such as
Wireless USB LAN Adapter rare referred to as LAN adapters.

LAN ADAPTER

 Functions of LAN Adapter:-


The computer and the card must communicate with
each other so that they can proceed to exchange information. In this way, the
computer allocates part of its memory to cards that have DMA (Direct memory
access).The card interface indicates that another computer is requesting data from the
computer. The computer bus transfers the data from the computer memory to the
network card.
N
etworking Devices

 Router:-
Routers are networking devices operating at layer 3 or a network layer of the
OSI model. They are responsible for receiving, analyzing, and forwarding data packets
among the connected computer networks. When a data
packet arrives, the router inspects the destination
address, consults its routing tables to decide the optimal
route and then transfers the packet along this route.

 How a router works:-


A router examines a packet header's destination IP address and
compares it against a routing table to determine the packet's best next hop. Routing
tables list directions for forwarding data to particular network destinations, sometimes
in the context of other variables, like cost. They amount to an algorithmic set of rules
that calculate the best way to transmit traffic toward any given IP address. A routing
table often specifies a default route, which the router uses whenever it fails to find a
better forwarding option for a given packet. For example, the typical home office
router directs all outbound traffic along a single default route to its internet service
provider (ISP) Routing tables can be static -- i.e., manually configured -- or dynamic.
Dynamic routers automatically updated their routing tables based on network activity,
exchanging information with other devices via routing protocols.

 Hub:-
A Network Hub is one of the most commonly used networking devices can be easily found
on any small networks such as home or office. Hub
operates at the physical layer of OSI model. It is the
simplest networking device hence has low cost.
Basically, a hub is a repeater with multiple ports. The
function of a hub in networking is similar to the
repeater. It transfers data in the form of binary bits and
uses for broadcasting data.

 Working of Hubs:-When a host sends frames, the hub forwards the frames in all
the ports. Hubs do not separate the type of the frame, for example, whether the frame
unicast should be either multicast or
broadcast. Hubs forward all the frames
into all the ports. Although a hub sends
the frames to all the ports, a computer
accepts the ones, whose MAC match
matches the destination MAC address
field. The rest of the frames are discarded
after receiving the required information.
 Switch:-
A switch is a Networking device in a computer network that connects other
devices together. Multiple data cables are plugged into a switch to enable
communication between
different networked
devices. Switches manage
the flow of data across a
network by transmitting a
received network packet
only to the one or more
devices for which the
packet is intended.

Diagram- Switch

 Working of Switch:-Whenever a host sends a frame to any other host, then the
source host is stored with the port in the address table of the MAC address switch. A
switch always stores the address of the source in the table. Unless a host does send
some data, its MAC address and port number will not be stored in the table of the
switch. Unless a host does send some data, its MAC address and port number will not
be stored in the table of the switch. When you initialize the switch, the switch does
not contain any information about any host and its address. In such a situation, when a
host frame sends, its MAC address is stored in the table but due to no destination
information, the switch sends the frame to all the hosts .When you initialize the
switch,the switch does not contain any information about any host and its address. In
such a situation, when a host frame sends, its MAC address is stored in the table but
due to no destination information, the switch sends the frame to all the hosts. As soon
as the second host sends some data, its address also gets stored in the table. As soon as
the second host sends some data, its address also gets stored in the table. Whenever a
host sends the frames, the switch stores it if its address is not already present in the
table. Thus a switch
creates its table.
When all the hosts'
addresses and port
numbers come in the
switch, the switch
delivers the frame to
all hosts only,
delivering the same
host to the host for
which the data has
been sent.
Bridge is termed as a network device which is helpful in filtering the data
load of the traffic by dividing it into segments or packets. They are used to lower the
load of traffic on the LAN and other networks. Bridges are passive devices, because
there is no interaction between
bridged and the paths of bridging.
Bridges operate on the second
layer of the OSI model that is the
data link layer.

Diagram: Working of Switch

 Working of Bridge:-
When various network segments are established at the data
link layer of the OSI model, we refer to it as bridge. However when the packets
ofdata are transferred along a network , without locating the network addresses this
process is termed as bridging. The process of bridging is helpful in locating the
addresses of unknown addresses to which it is viable to send data. In bridging the
data packets contain a header or a packet header which holds the address to the
intended device. Bridge can remember and recall the address of the devices for
further transmission. There are two kinds of bridging modes, the transparent bridging
and the source routing bridging. When the process of bridging occurs, it makes a
bridging table along side where it stores the MAC addresses of the various
terminals. Thistable helps the bridges to send the data packet to the exact location
next time. However when a specific address does not meet the contents of the
bridging table, the data packet is forwarded further ahead to every attached terminal
in LAN except from the computer it is connected to. This type of bridging is called
transparent bridging. When the source computer presents pathway information
within the packet, this typeof bridging is known as source route bridging. It is most
commonly used in used on Token Ring networks.

 Repeater:-
A repeater is a network device that retransmits a received signal with more power
and to an extended geographical or topological network boundary than what would be
capable with the original signal repeater is implemented in computer networks to
expand the coverage area of the network, re propagate a weak or broken signal and or
service remote nodes. Repeaters amplify the received/input signal to a higher frequency
domain so that it is reusable, scalable.
Diagram: Repeater

 Working of Repeater:-
When an electrical signal is transmitted via a channel, it
gets attenuated depending upon the nature of the channel or the technology. This poses
a limitation upon the length of the LAN or coverage area of cellular networks. This
problem is alleviated by installing repeaters at certain intervals.

Repeaters amplifies the


attenuated signal and then
retransmits it. Digital
repeaters can even
reconstruct signals distorted
by transmission loss. So,
repeaters are popularly
incorporated to connect
between two LANs thus
forming a large single LAN

Diagram: Working of Repeater

 Gateway:-
The link between two computers to connect to internet or another
network is called gateway. The gateway works like a portal among two programs by
means of communications between protocol
and permit them to share data on same
computers or among different computers.
Gateways are also known as protocol
converter that can perform at any OSI
model layer. The task of a gateway is very
complex.
 Working of Gateway:-
A gateway is a network point that works as an access to another
network. Generally in intranet a node can be either a gateway node or the nodes that join
the network are gateways. In large organization where the computers control the traffic
between organization networks are gateway nodes. Like that the computers used by ISP to
connect different user with each other at a time to the internet are gateway nodes. In a
project of any business company computer server work as a gateway nodes and it may be
proxy server or firewall some time. A
gateway may connected to a router because
a router exactly known where to through a
given packet of data that appears at the
gateway then a switch finalize the actual in
and out path of the gateway for the specified
packet .A gateway is a compulsory features
of routes even though other devices can
perform as a gateway. The operating system
mostly used this term and internet
connection sharing act as a gateway and
creating a connection among internal
network.

Diagram: Working of Gateways


Ex No 4: Implementation of Error Detection and ErrorCorrection Techniques.

Date :

Aim :

Algorithm:

Programme:

Parity bit Method :

#include<stdio.h>

#include<string.h>

int main()

int count=0;

int i,parity;

char data[20];

printf("enter data\n");

scanf("%s",&data);

int l=strlen(data);

printf("choose parity\n0:Even\n1:Odd");

scanf("%d",&parity);

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

if(data[i]=='1')

count++;
}

if(parity==0 && count%2==0)

printf("No error detected\n");

else if(parity==1&&count%2==1)

printf("No error detected\n");

else

printf("error detected\n");

return 0;

2. CRC Method:

#include <stdio.h>

#include <conio.h>

#include <string.h>

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

}
Sample Output

Parity bit Method :

1.Enter data : 01011011

Choose Parity

0 : Even 1 : Odd

Error Detected

2. Enter data : 01011011

Choose Parity

0 : Even 1 : Odd

No Error Detected
5. Flow control mechanisms

Date :

Aim :

Algorithm

Go Back N protocol in java

import java.io.*;
public class GoBackN {

public static void main(String args[]) throws IOException


{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));

System.out.println("Please enter the Window Size: ");


int window = Integer.parseInt(br.readLine());

boolean loop = true;


int sent = 0;

while(loop)
{

for(int i = 0; i < window; i++)


{
System.out.println("Frame " + sent + " has been transmitted.");
sent++;
if(sent == window)
break;
}

System.out.println("Please enter the last Acknowledgement received.");


int ack = Integer.parseInt(br.readLine());

if(ack == window)
loop = false;
else
sent = ack;
}

}
output:-

Please enter the Window Size:


7
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Please enter the last Acknowledgement received.
Ex No : 06 Implementation of Distance vector routing algorithm

Date:

Aim :

Algorithm

Programme

#include<stdio.h>

struct node

unsigned dist[20];

unsigned from[20];

}rt[10];

int main()

int costmat[20][20];

int nodes,i,j,k,count=0;

printf("\nEnter the number of nodes : ");

scanf("%d",&nodes);//Enter the nodes

printf("\nEnter the cost matrix :\n");

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

{
for(j=0;j<nodes;j++)

scanf("%d",&costmat[i][j]);

costmat[i][i]=0;

rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix

rt[i].from[j]=j;

do

count=0;

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=0;j<nodes;j++)

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

if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])

{//We calculate the minimum distance

rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];

rt[i].from[j]=k;

count++;

}while(count!=0);

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

{
printf("\n\n For router %d\n",i+1);

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

printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);

printf("\n\n");

getch();

/*

Output

Enter the number of nodes :

Enter the cost matrix :

027

201

710

For router 1

node 1 via 1 Distance 0


node 2 via 2 Distance 2

node 3 via 3 Distance 3

For router 2

node 1 via 1 Distance 2

node 2 via 2 Distance 0

node 3 via 3 Distance 1

For router 3

node 1 via 1 Distance 3

node 2 via 2 Distance 1

node 3 via 3 Distance 0

*/
Ex No : 8 Client Server Program using UDP (Chat application)

Date:

Aim:

To write a Client Server Program to create chat application using UDP.

Algorithm:

******* Write algorithm steps yourself**********

Program:

Client:

import java.io.*;

import java.net.*;

class UDPClient

public static void main(String args[]) throws Exception

BufferedReader inFromUser =

new BufferedReader(new InputStreamReader(System.in));

DatagramSocket clientSocket = new DatagramSocket();

InetAddress IPAddress = InetAddress.getByName("localhost");

byte[] sendData = new byte[1024];

byte[] receiveData = new byte[1024];


String sentence = inFromUser.readLine();

sendData = sentence.getBytes();

DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

clientSocket.send(sendPacket);

DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

clientSocket.receive(receivePacket);

String modifiedSentence = new String(receivePacket.getData());

System.out.println("FROM SERVER:" + modifiedSentence);

clientSocket.close();

Server:

import java.io.*;

import java.net.*;

class UDPServer

public static void main(String args[]) throws Exception

DatagramSocket serverSocket = new DatagramSocket(9876);

byte[] receiveData = new byte[1024];

byte[] sendData = new byte[1024];

while(true)

DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData());

System.out.println("RECEIVED: " + sentence);

InetAddress IPAddress = receivePacket.getAddress();

int port = receivePacket.getPort();

String capitalizedSentence = sentence.toUpperCase();

sendData = capitalizedSentence.getBytes();

DatagramPacket sendPacket =

new DatagramPacket(sendData, sendData.length, IPAddress, port);

serverSocket.send(sendPacket);

OUTPUT:

E:\Mahendra\CN\cnlab>cd "Network programming Final Programs"

E:\Mahendra\CN\cnlab\Network programming Final Programs>javac UDPClient.

E:\Mahendra\CN\cnlab\Network programming Final Programs>java UDPClient

hai

FROM SERVER:HAI

E:\Mahendra\CN\cnlab\Network programming Final Programs>java UDPClient

hello

FROM SERVER:HELLO

RESULT:

Thus the Client Server Program to create chat application using UDP executed successfully.
EX.NO:9 USE UDP SOCKET FOR IMPLEMENTING DNS

Date:

Aim

To write a java program for DNS application program using UDP.

Algorithm

• Start the program.

• Get the frame size from the user

• To create the frame based on the user request.

• To send frames to server from the client side.

• If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.

• Stop the program

PROGRAM :

UDP DNS Server

Import java.io.*;

Imporjava.net.*;

public class udpdnsserver

private static int indexOf(String[] array, String str)


{

str = str.trim();

for (int i=0; i < array.length; i++)

if (array[i].equals(str)) return i;

return -1;

public static void main(String arg[])throws IOException

String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};

String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"};


System.out.println("Press Ctrl + C to Quit");

while (true)

DatagramSocket serversocket=new DatagramSocket(1362);

byte[] senddata = new byte[1021];

byte[] receivedata = new byte[1021];

DatagramPacket recvpack = new DatagramPacket (receivedata, receivedata.length);


serversocket.receive(recvpack);

String sen = new String(recvpack.getData());

InetAddress ipaddress = recvpack.getAddress(); int port = recvpack.getPort();

String capsent;

System.out.println("Request for host " + sen);

if(indexOf (hosts, sen) != -1) capsent = ip[indexOf (hosts, sen)];

else capsent = "Host Not Found"; senddata = capsent.getBytes();


DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);
serversocket.send(pack);

serversocket.close();

UDP DNS Client–

import java.io.*;

import java.net.*;

public class udpdnsclient

public static void main(String args[])throws IOException

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket


clientsocket = new DatagramSocket();

InetAddress ipaddress; if (args.length == 0)

ipaddress = InetAddress.getLocalHost(); else

ipaddress = InetAddress.getByName(args[0]); byte[] senddata = new byte[1024];

System.out.print("Enter the hostname : "); String sentence = br.readLine();

Senddata = sentence.getBytes();

DatagramPacket pack = new DatagramPacket(senddata,senddata.length, ipaddress,portaddr);


clientsocket.send(pack);

DatagramPacket recvpack =newDatagramPacket(receivedata,receivedata.length);


clientsocket.receive(recvpack);

String modified = new String(recvpack.getData());

System.out.println("IP Address: " + modified);

clientsocket.close();

OUTPUT

Server

$ javac udpdnsserver.java $ java udpdnsserver Press Ctrl + C to Quit Request for host yahoo.com
Request for host cricinfo.com Request for host youtube.com

Client

$ javac udpdnsclient.java $ java udpdnsclient Enter the hostname : yahoo.com IP Address:


68.180.206.184 $ java udpdnsclient Enter the hostname : cricinfo.com IP Address: 80.168.92.140 $
java udpdnsclient Enter the hostname : youtube.com IP Address: Host Not Found
10. Implementation of Layers for security protocols - SSL/TLS

Aim:

Set up the Server

 Create a Java class and name it as SSLServer.

package server;

import javax.net.ssl.*;

import java.io.*;

import java.security.*;

public class SSLServer {

private static final int PORT = 1234;

public static void main(String[] args) {

try {

// Load keystore containing server's private key and certificate

char[] password = "password".toCharArray();

KeyStore keyStore = KeyStore.getInstance("JKS");

try (FileInputStream fis = new FileInputStream("server.keystore")) {

keyStore.load(fis, password);

}
// Create key manager factory

KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");

kmf.init(keyStore, password);

// Create SSL context

SSLContext sslContext = SSLContext.getInstance("TLS");

sslContext.init(kmf.getKeyManagers(), null, null);

// Create SSL server socket factory

SSLServerSocketFactory ssf = sslContext.getServerSocketFactory();

// Create SSL server socket

try (SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket(PORT)) {

System.out.println("Server started. Waiting for client...");

// Accept incoming connections

try (SSLSocket clientSocket = (SSLSocket) serverSocket.accept()) {

System.out.println("Client connected.");

// Perform communication with client

try (BufferedReader in = new BufferedReader(new


InputStreamReader(clientSocket.getInputStream()));

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {

String message;
while ((message = in.readLine()) != null) {

System.out.println("Received from client: " + message);

out.println("Server received: " + message);

} catch (Exception e) {

e.printStackTrace();

Set up Client

 Create a Java class and name it as SSLClient.

package client;

import javax.net.ssl.*;

import java.io.*;

import java.security.*;

import java.security.cert.CertificateException;

import java.security.cert.X509Certificate;

public class SSLClient {

private static final String SERVER_HOST = "localhost";


private static final int SERVER_PORT = 1234;

public static void main(String[] args) {

try {

// Create trust manager that trusts all certificates

TrustManager[] trustManagers = new TrustManager[]{

new X509TrustManager() {

@Override

public void checkClientTrusted(X509Certificate[] x509Certificates, String s)

throws CertificateException {

@Override

public void checkServerTrusted(X509Certificate[] x509Certificates, String s)

throws CertificateException {

@Override

public X509Certificate[] getAcceptedIssuers() {

return new X509Certificate[0];

};

// Create SSL context


SSLContext sslContext = SSLContext.getInstance("TLS");

sslContext.init(null, trustManagers, new SecureRandom());

// Create SSL socket factory

SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

// Create SSL socket

try (SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(SERVER_HOST, SERVER_PORT);

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) {

// Send a message to the server

out.println("Hello, Server!");

// Read the response from the server

String response = in.readLine();

System.out.println("Received from server: " + response);

} catch (Exception e) {

e.printStackTrace();

OutOPut

You might also like