CN Lab Manual
CN Lab Manual
1 Study of Network devices in detail and connect the computers in Local Area Network. 1- 9
2 Write a Program to implement the data link layer farming methods such as 10-13
3 Write a Program to implement data link layer farming method checksum. 14-17
4 Write a program for Hamming Code generation for error detection and correction. 18-19
5 Write a Program to implement on a data set of characters the three CRC polynomials – 20-21
CRC 12, CRC 16 and CRC CCIP.
7 Write a Program to implement Sliding window protocol for Selective repeat. 25-26
9 Write a program for congestion control using leaky bucket algorithm 32-34
10 Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path through 35-37
a graph.
11 Write a Program to implement Distance vector routing algorithm by obtaining routing 38-39
table at each node (Take an example subnet graph with weights indicating delay between
nodes).
Hardware devices that are used to connect computers, printers, fax machines and other
electronic devices to a network are called network devices. These devices transfer data in a
fast, secure and correct way over same or different networks. Network devices may be inter-
network or intra-network.
1.Modem
2.RJ45 Connector
3.Ethernet Card(NIC)
4.Router
5.Switch
6.Gateway
7.WiFi-Card
8.Repeater
9.Hub
10.Bridge
11.Brouter
1. Modem
Modem is a device that enables a computer to send or receive data over telephone or cable
lines. The data stored on the computer is digital whereas a telephone line or cable wire can
transmit only analog data
1
modulator and demodulator. The modulator converts digital data into analog data when
the data is being sent by the computer. The demodulator converts analog data signals into
digital data when it is being received by the computer.
Early modems were devices that used audible sounds suitable for transmission over
traditional telephone systems and leased lines. These generally operated at 110 or 300 bits
per second (bit/s), and the connection between devices was normally manual, using an
attached telephone handset.
By the 1970s, higher speeds of 1200 and 2400 bit/s for asynchronous dial
connections, 4800 bit/s for synchronous leased line connections and 35 kbit/s for
synchronous conditioned leased lines were available. By the 1980s, less expensive 1200 and
2400 bit/s dialup modems were being released, and modems working on radio and other
systems were available. As device sophistication grew rapidly in the late 1990s, telephone-
based modems quickly exhausted the available bandwidth, reaching the ultimate standard of
56 kbit/s.
Types of Modem
· Simplex − A simplex modem can transfer data in only one direction, from digital
device to network (modulator) or network to digital device (demodulator).
· Half duplex − A half-duplex modem has the capacity to transfer data in both the
directions but only one at a time.
· Full duplex − A full duplex modem can transmit data in both the directions
simultaneously.
2. RJ45 Connector
RJ45 is the acronym for Registered Jack 45. RJ45 connector is an 8-pin jack used by devices
to physically connect to Ethernet based local area networks (LANs). Ethernet is a technology
that defines protocols for establishing a LAN.
RJ45 connector pins at both ends. These pins go into the corresponding socket on devices
and connect the device to the network.
RJ-45 connectors have 8 pins and these are typically used to connect Ethernet cables to a
switch or serial data modem. You would commonly find switches with RJ45 connectors in
copper cable networks. Some switches have RJ45 as well as SFP fiber ports and hence these
can be used in fiber networks as well.
2
3. Ethernet Card
Ethernet card, also known as network interface card (NIC), is a hardware component used by
computers to connect to Ethernet LAN and communicate with other devices on the LAN.
The NIC has RJ45 socket where network cable is physically plugged in.
Ethernet card speeds may vary depending upon the protocols it supports. Old Ethernet cards
had maximum speed of 10 Mbps. However, modern cards support fast Ethernets up to a speed
of 100 Mbps. Some cards even have capacity of 1 Gbps.
Also called a "network interface card" (NIC), an Ethernet adapter is a card that plugs
into a slot on the motherboard and enables a computer to access an Ethernet network
(LAN). In the past, desktop computers always used cards. Today, Ethernet is built into
the chipsets on the motherboards of desktop and laptop computers.
4. Router
A router is a network layer hardware device that transmits data from one LAN to another if
both networks support the same set of protocols. So a router is typically connected to at least
two LANs and the internet service provider (ISP). It receives its data in the form of packets,
which are data frames with their destination address added. Router also strengthens the
signals before transmitting them. That is why it is also called repeater.
Old desktop computers can be retrofitted with an adapter that plugs into an available PCI slot. A
USB-based Ethernet adapter can also retrofit both laptop and desktop machines. In years past,
non-USB laptops were updated with PC Cards and ExpressCards .
3
5. Switch
Switch is a network device that connects other devices to Ethernet networks through twisted
pair cables. It uses packet switching technique to receive, store and forward data packets
on the network.
Higher data speeds are achieved on networks through use of multiple switches.
Features of Switches
· A switch operates in the layer 2, i.e. data link layer of the OSI model.
· It is an intelligent network device that can be conceived as a multiport network
bridge.
· It uses MAC addresses (addresses of medium access control sublayer) to send data
packets to selected destination ports.
· It uses packet switching technique to receive and forward data packets from the
source to the destination device.
· It is supports unicast (one-to-one), multicast (one-to-many) and broadcast (one-to-all)
communications.
· Transmission mode is full duplex, i.e. communication in the channel occurs in both
the directions at the same time. Due to this, collisions do not occur.
· Switches are active devices, equipped with network software and network
management capabilities.
4
· Switches can perform some error checking before forwarding data to the destined
port.
· The number of ports is higher – 24/48.
6. Gateway
Gateway is a network device used to connect two or more dissimilar networks. In networking
parlance, networks that use different protocols are dissimilar networks. A gateway usually is a
computer with multiple NICs connected to different networks.
Gateway uses packet switching technique to transmit data from one network to another. In
this way it is similar to a router, the only difference being router can transmit data only over
networks that use same protocols.
A gateway is a network node used in telecommunications that connects two networks with
different transmission protocols together. Gateways serve as an entry and exit point for a
network as all data must pass through or communicate with the gateway prior to being routed.
In most IP-based networks, the only traffic that does not go through at least one gateway is
traffic flowing among nodes on the same local area network (LAN) segment. The term default
gateway or network gateway may also be used to describe the same concept.
The primary advantage of using a gateway in personal or enterprise scenarios is simplifying
internet connectivity into one device. In the enterprise, a gateway node can also act as a proxy
server and a firewall. Gateways can be purchased through popular technology retailers, such as
Best Buy, or rented through an internet service provider.
5
7. Wi-Fi Card
Wi-Fi is the acronym for wireless fidelity. Wi-Fi technology is used to achieve wireless
connection to any network. Wi-Fi card is a card used to connect any device to the local
network wirelessly. The physical area of the network which provides internet access through Wi-
Fi is called Wi-Fi hotspot. Hotspots can be set up at home, office or any public space. Hotspots
themselves are connected to the network through wires.
A Wi-Fi card is used to add capabilities like teleconferencing, downloading digital camera
images, video chat, etc. to old devices. Modern devices come with their in-built wireless
network adapter.
On the technical side, the IEEE 802.11 standard defines the protocols that enable
communications with current Wi-Fi-enabled wireless devices, including wireless routers and
wireless access points. Wireless access points support different IEEE standards.
Each standard is an amendment that was ratified over time. The standards operate on varying
frequencies, deliver different bandwidth, and support different numbers of channels.
8. Repeater
A repeater operates at the physical layer. Its job is to regenerate the signal over the same
network before the signal becomes too weak or corrupted so as to extend the length to which
the signal can be transmitted over the same network.
They do not amplify the signal. When the signal becomes weak, they copy the signal bit by bit
and regenerate it at the original strength. It is a 2 port device.
Why are Repeaters needed?
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.
6
Types of Repeaters
According to the types of signals that they regenerate, repeaters can be classified into two
categories −
9. Hub
A hub is basically a multiport repeater. A hub connects multiple wires coming from different
branches, for example, the connector in star topology which connects different stations. Hubs
cannot filter data, so data packets are sent to all connected devices.
Also, they do not have the intelligence to find out the best path for data packets which leads to
inefficiencies and wastage.
Types of Hub
a)Active Hub
b) Passive Hub
c) Intelligent Hub
Network hubs are categorized as Layer 1 devices in the Open Systems Interconnection (OSI)
reference model. They connect multiple computers together, transmitting data received at one
port to all of its other ports without restriction. Hubs operate in half-duplex.
This model raises security and privacy concerns, because traffic could not be safeguarded or
quarantined. It also presents a practical issue in terms of traffic management. Devices on a hub
function as a network segment and share a collision domain. Thus, when two devices
connected to a network hub transmit data simultaneously, the packets will collide, causing
network performance problems. This is mitigated in switches or routers, as each port represents
a separate collision domain.
7
10. Bridge
A bridge operates at the 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
a) Transparent Bridges
b) Source Routing Bridges
Uses of Bridge
· Bridges connects two or more different LANs that has a similar protocol and provides
communication between the devices (nodes) in them.
· By joining multiple LANs, bridges help in multiplying the network capacity of a
single LAN.
· Since they operate at data link layer, they transmit data as data frames. On receiving a
data frame, the bridge consults a database to decide whether to pass, transmit or discard
the frame.
8
o If the frame has a destination MAC (media access control) address in the same
network, the bridge passes the frame to that node and then discards it.
o If the frame has a destination MAC address in a connected network, it will
forward the frame toward it.
· By deciding whether to forward or discard a frame, it prevents a single faulty node
from bringing down the entire network.
· In cases where the destination MAC address is not available, bridges can broadcast
data frames to each node. To discover new segments, they maintain the MAC address
table.
· In order to provide full functional support, bridges ideally need to be transparent. No
major hardware, software or architectural changes should be required for their
installation.
· Bridges can switch any kind of packets, be it IP packets or AppleTalk packets, from
the network layer above. This is because bridges do not examine the payload field of the
data frame that arrives, but simply looks at the MAC address for switching.
· Bridges also connect virtual LANs (VLANs) to make a larger VLAN.
· A wireless bridge is used to connect wireless networks or networks having a wireless
segment.
11. Brouter
It is also known as the bridging router is a device that combines features of both bridge and
router. It can work either at the data link layer or a network layer. Working as a router, it is
capable of routing packets across networks, and working as the bridge, it is capable of filtering
local area network traffic.
Brouters operate at both the network layer for routable protocols and at the data link
layer for non-routable protocols. As networks continue to become more complex, a mix of
routable and non-routable protocols has led to the need for the combined features of bridges
and routers. Brouters handle both routable and non-routable features by acting as routers for
routable protocols and bridges for non-routable protocols. Bridged protocols might propagate
throughout the network, but techniques such as filtering and learning might be used to reduce
potential congestion.
9
Write a Program to implement the data link layer farming methods such as
i) Character stuffing ii) bit stuffing.
BIT STUFFING:
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0; count=1; j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1 && k<n && count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
10
}
OUT PUT:
11
CHARACTER STUFFING :
#include<stdio.h>
void main()
{
int i,j,n,k,count,a[20],b[20];
char d[20];
printf("Enter the number of characters : ");
scanf("%d",&n);
printf("Enter the characters : ");
scanf("%s",d);
printf("The original data : %s\n",d);
printf("The transmitted data : dlestx",d);
for(i=0;i<n;i++)
{
j=i;
if(d[j]=='d')
{
if(d[++j]=='l')
{
if(d[++j]=='e')
{
printf("dle");
}
}
}
printf("%c",d[i]);
}
printf("dleetx");
printf("\nThe received data : %s",d);
printf("\n");
}
12
# include
13
3) Write a program to implement datalink layer framing method checksum
Source Code:
#include<stdio.h>
#include<conio.h>
int add(int, int);
int com(int);
void main()
{
int i, j, dl, dil;
int data1[10], data2[10], newdata[10], comp[10], checksum[10];
printf("\n Enter the data length=");
scanf("%d", &dl);
printf("\n Enter the data1 : \n");
for (i = 0; i < dl; i++)
scanf("%d", &data1[i]);
printf("\n Enter the data2 : \n");
for (i = 0; i < dl; i++)
scanf("%d", &data2[i]);
for (i = dl - 1; i >= 0; i--)
{
newdata[i] = add(data1[i], data2[i]);
}
14
printf("\n\n Receiver Side : \n");
printf("\n Data : ");
for (i = 0; i < dl; i++)
printf("%d", data1[i]);
printf("");
for (i = 0; i < dl; i++)
printf("%d", data2[i]);
printf("");
for (i = 0; i < dl; i++)
printf("%d", checksum[i]);
15
return 1;
}
else if (x == 1 && y == 0 && carry == 1)
{
carry = 1;
return 0;
}
else if (x == 0 && y == 1 && carry == 0)
{
carry = 0;
return 1;
}
else if (x == 0 && y == 1 && carry == 1)
{
carry = 1;
return 0;
}
else if (x == 0 && y == 0 && carry == 0)
{
carry = 0;
return 0;
}
else
{
carry = 0;
return 1;
}
}
int com(int a)
{
if (a == 0)
return 1;
else
return 0;
}
16
OUTPUT:
Enter the data length:6
Enter the data 1:
101010
Enter the data 2:
111000
The new data is:1 0 0 0 1 0
Checksum:0 1 1 1 0 1
Receiver side:
Data:1 0 1 0 1 0 1 1 1 0 0 0 0 011101
Addition:00000000
17
4. Write a program for Hamming code generation for Error detection and Error
correction
Source Code:
#include<stdio.h>
int main()
{
int a[4],b[4],r[3], s[3],i,q[3];
printf("\nEnter 4 bit message word one by one:\n");
for(i=3;i>=0;i--)
{
scanf("%d",&a[i]);
}
r[0]=(a[2]+a[1]+a[0])%2;
r[1]=(a[2]+a[1]+a[3])%2;
r[2]=(a[0]+a[1]+a[3])%2;
for(i=3;i>=0;i--)
scanf("%d",&b[i]);
18
//calculating syndrome bits
s[0]= (b[2]+b[1]+b[0]+r[0])%2;
s[1]= (b[3]+b[2]+b[1]+r[1])%2;
s[2]= (b[0]+b[1]+b[3]+r[2])%2;
printf("\nsyndrome is: \n");
for(i=2; i>=0;i--)
{
printf("%d",s[i]);
}
if((s[2]==0) && (s[1]==0) && (s[0]==0))
printf("\n RECIEVED WORD IS ERROR FREE\n");
if((s[2]==1) && (s[1]==0) && (s[0]==1))
printf("\nrecieved word is error with error in 1bit(b0) position from right\n");
if((s[2]==1) && (s[1]==1) && (s[0]==1))
printf("\nrecieved word is error with error in 2bit(b1) position from right\n");
if((s[2]==0) && (s[1]==1) && (s[0]==1))
printf("\nrecieved word is error with error in 3bit(b2) position from right\n");
if((s[2]==1) && (s[1]==1) && (s[0]==0))
printf("\nrecieved word is error with error in 4bit(b3) position from right\n");
return(1);
}
OUTPUT:
Enter 4 bit message word one by one:
1100
The 7bit hamming code word:
1 1 0 0 1 0 1
Enter the recieved word: 1 1 0 0 1 0 1
syndrome is:
000
RECIEVED WORD IS ERROR FREE
19
5. Write a Program to implement on a data set of characters the three CRC polynomials –
CRC 12, CRC 16 and CRC CCIP.
Source Code:
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int i,j,k,m,n,cl;
char a[10],b[100],c[100];
20
b) Verify the CRC code
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int i,j,k,m,n,cl;
char a[10],c[100];
21
22
6. Write a Program to implement Sliding window protocol for Goback N.
Source Code:
#include<stdio.h>
int main()
int windowsize,sent=0,ack,i;
scanf("%d",&windowsize);
while(1)
sent++;
if(sent == windowsize)
break;
scanf("%d",&ack);
if(ack == windowsize)
break;
else
sent = ack;
return 0;
23
Output:
24
7. Write a Program to implement Sliding window protocol for Selective repeat.
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent
by the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
25
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}
Output:
Enter 6 frames: 1 0 4 5 6 8
With sliding window protocol the frames will be sent in the following manner (assuming
no corruption of frames)
After sending 2 frames at each stage sender waits for acknowledgement sent by the
receiver
10
Acknowledgement of above frames sent is received by sender
45
Acknowledgement of above frames sent is received by sender
68
Acknowledgement of above frames sent is received by sender
26
8. Write a Program to implement Stop and Wait Protocol.
Source Code:
#include<stdio.h>
// Function declarations
int sender(int i, int frame[]);
int recv(int i);
// Global variables
int timer = 0, wait_for_ack = -1, frameQ = 0, cansend = 1, t = 0;
int main() {
int i, j;
int frame[5]; // Assuming an array of 5 frames
for (i = 0; i < 10; i++) { // Run the loop for a time duration, assuming 10 time units
sender(i, frame);
recv(i);
}
return 0;
}
if (wait_for_ack == 3) {
if (i == frame[t]) {
frameQ++;
t++;
}
if (frameQ == 0) {
printf("NO FRAME TO SEND at time=%d \n", i);
}
27
cansend = -1;
frameQ--;
timer++;
printf("timer in sender=%d\n", timer);
}
printf("frameQ=%d\n", frameQ);
printf("i=%d t=%d\n", i, t);
if (t < 5) { // Check array bounds
printf("value in frame=%d\n", frame[t]);
}
}
return 0;
}
int recv(int i) {
printf("timer in recv=%d\n", timer);
if (timer > 0) {
timer++;
}
if (timer == 3) {
printf("FRAME ARRIVED AT TIME=%d\n", i);
wait_for_ack = 0;
timer = 0;
cansend = 1; // Reset to allow sending the next frame
} else {
printf("WAITING FOR FRAME AT TIME=%d\n", i);
}
return 0;
}
Output:
28
NO FRAME TO SEND at time=0
frameQ=0
i=0 t=0
value in frame=2
timer in recv=0
WAITING FOR FRAME AT TIME 0
29
value in frame=5
timer in recv=3
FRAME ARRIVED AT TIME= 4
30
WAITING FOR FRAME AT TIME 8
31
9. Write a program for congestion control using leaky bucket algorithm
Source Code:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main() {
int i, packets[10], content = 0, newcontent, time, clk, bcktsize, oprate;
// Process packets
for (i = 0; i < 5; ++i) {
if ((packets[i] + content) > bcktsize) {
if (packets[i] > bcktsize) {
printf("\nIncoming packet size %d greater than the size of the bucket\n",
packets[i]);
} else {
printf("\nBucket size exceeded\n");
}
} else {
newcontent = packets[i];
content += newcontent;
printf("\nIncoming Packet: %d\n", newcontent);
printf("Transmission left: %d\n", content);
32
printf("\nTime left until next packet: %d seconds", (time - clk));
sleep(1); // Simulate time passing
if (content > 0) {
printf("\nTransmitted\n");
if (content <= oprate) {
content = 0;
} else {
content -= oprate;
}
printf("Bytes remaining: %d\n", content);
} else {
printf("\nNo packets to send\n");
}
}
}
}
return 0;
}
Output:
Enter output rate of the bucket: 5
Enter Bucket size: 10
33
Incoming Packet: 3
Transmission left: 3
Next packet will come at 5 seconds
Time left until next packet: 5 seconds
Transmitted
Bytes remaining: 0
Incoming Packet: 6
Transmission left: 6
Next packet will come at 6 seconds
Time left until next packet: 6 seconds
Transmitted
Bytes remaining: 1
Time left until next packet: 5 seconds
Transmitted
Bytes remaining: 0
Incoming Packet: 7
Transmission left: 7
Next packet will come at 2 seconds
Time left until next packet: 2 seconds
Transmitted
Bytes remaining: 2
Time left until next packet: 1 seconds
Transmitted
Bytes remaining: 0
Incoming Packet: 5
Transmission left: 5
Next packet will come at 9 seconds
Time left until next packet: 9 seconds
Transmitted
Bytes remaining: 0
Incoming Packet: 3
Transmission left: 3
Next packet will come at 1 seconds
Time left until next packet: 1 seconds
Transmitted
Bytes remaining: 0
34
10. Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path
through a graph
Source Code:
#include<stdio.h>
#define INFINITY 9999
#define MAX 10
void dij(int g[MAX][MAX],int n,int stnode);
int main()
{
int g[MAX][MAX],i,j,n,u;
printf("Enter number of vertices : ");
scanf("%d",&n);
printf("Enter the adjacency matrix\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&g[i][j]);
printf("Enter the starting node : ");
scanf("%d",&u);
dij(g,n,u);
return 0;
}
void dij(int g[MAX][MAX],int n,int stnode)
{
int cost[MAX][MAX],dist[MAX],pred[MAX];
int vis[MAX],count,mindist,nextnode,i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(g[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=g[i][j];
}
}
for(i=0;i<n;i++)
{
dist[i]=cost[stnode][i];
pred[i]=stnode;
vis[i]=0;
}
35
dist[stnode]=0;
vis[stnode]=1;
count=1;
while(count<n-1)
{
mindist=INFINITY;
for(i=0;i<n;i++)
{
if(dist[i]<mindist&&!vis[i])
{
mindist=dist[i];
nextnode=i;
}
}
vis[nextnode]=1;
for(i=0;i<n;i++)
{
if(!vis[i])
{
if(mindist+cost[nextnode][i]<dist[i])
{
dist[i]=mindist+cost[nextnode][i];
pred[i]=nextnode;
}
}
}
count++;
}
for(i=0;i<n;i++)
{
if(i!=stnode)
{
printf("Distance of node %d = %d\n",i,dist[i]);
printf("Path = %d",i);
j=i;
do
{
j=pred[j];
printf(" <- %d",j);
}while(j!=stnode);
printf("\n");
}
}
}
36
Output:
37
11. Write a Program to implement Distance vector routing algorithm by obtaining routing table at
eachnode (Take an example subnet graph with weights indicating delay between nodes).
Program:
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}
rt[10];
int main()
{
int cost[10][10],n,i,j,k,count=0;
printf("Enter the number of nodes : ");
scanf("%d",&n);
printf("Enter the cost matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&cost[i][j]);
cost[i][i]=0;
rt[i].dist[j]=cost[i][j];
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>cost[i][k]+rt[k].dist[j])
{
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<n;i++)
{
printf("For router %d\n",i+1);
for(j=0;j<n;j++)
{
printf("Node %d via %d distance
%d\n",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}printf("\n");
}
38
Output:
39
12. Write a Program to implement Broadcast tree by taking subnet of hosts.
Program :
#include<stdio.h>
#include<conio.h>
int n,weight[10][10]={0},intree[10]={0},d[10]={0},whoto[10]={0};
void updatedistance(int target)
{
int i;
for(i=0;i<n;i++)
{
if((weight[target][i]!=0)&&(d[i]>weight[target][i]))
{
d[i]=weight[target][i];
whoto[i]=target;
}
}
}
void main()
{
int i,j,total=0,s;
printf("Enter the number of nodes : ");
scanf("%d",&n);
printf("Enter distance from\n");
for(i=0;i<n;++i)
{
for(j=0;j<n;j++)
{
if(i==j)
weight[i][j]=0;
else
{
printf("%c --> %c : ", 'A'+i,'A'+j);
scanf("%d",&weight[i][j]);
}
}
}
printf("The Distance matrix is\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d ",weight[i][j]);
printf("\n");
}
for(i=0;i<n;i++)
d[i]=1000;
printf("Enter source from 0 to %d : ",n-1);
scanf("%d",&s);
printf("Broadcast tree for source node %c is\n",s+'A');
40
printf("Source\tDestination\n");
intree[s]=1;
updatedistance(s);
for(j=0;j<n-1;j++)
{
int min=-1;
for(i=0;i<n;i++)
{
if(!intree[i])
{
if((min==-1)||(d[min]>d[i]))
min=i;
}
}
printf("%c\t%c\n",whoto[min]+'A',min+'A');
intree[min]=1;
total+=d[min];
updatedistance(min);
}
printf("Total distance : %d\n",total);
}
Output :
41
42
43
44
45
46
47
48
49
50
51
52
53
https://nmap.org/download.html#windows
down load the above software and install on your machine at first
OS Detection in Nmap
NMAP stands for Network Mapper which is an open-source tool used for network
exploration and security auditing, in comparison to this, a tool named Nessus is used
by industry professionals. These tools are mainly used by cybersecurity experts and
hackers.
Its main purpose is:
Provide the list of the live host.
Find the open Ports.
The real-time information of a network.
OS and Port scanning.
The hackers and the cybersecurity expert need to know the Operating System of the
machine. It becomes very easy to access a system if we can know the specific open
ports or the security holes of the system. Network Mapper(NMAP) NMAP has a
database that helps in Operating systems (OS) but it is not automatically updated. The
database to detect an OS is located at ‘/usr/share/nmap/nmap-os-db’.
Operating System(OS) detection is a very long and hectic process. So, before we get
our hands dirty we should know about the five separate probes being performed to
determine the OS. This probe may consist of one or more packets. The response to
each packet (which is sent by the probe) by the target system helps to determine the
OS type.
The five different probes are:
Sequence Generation.
ICMP Echo.
TCP Explicit Congestion Notification.
TCP.
UDP.
1. Sequence Generation: The Sequence Generation Probe consists of six
packets that are sent 100 ms apart and are all TCP SYN packets. The result of
all these packets will help in Operating System(OS) detection.
2. ICMP Echo: Two ICMP request packets are sent to the target system with
different settings in the packet. The result of all these will help verify the OS type
by NMAP.
3. TCP Explicit Congestion Notification: Congestion is a slowdown that occurs
when a lot of packets are generated and passed by a single router. The packets
which are sent are mainly used to get back the responses from the target system.
This helps to detect the OS because a specific OS returns a specific value and
each OS handles a packet differently.
4. TCP: Six packets are sent during this probe, and some packets are sent to
open or closed ports with specific packet settings by using the corresponding
54
result we can determine the type of Operating System(OS). The TCP Packets
which are sent with varying flags are as follows:
no flags.
SYN, FIN, URG, and PSH.
ACK.
SYN.
ACK.
FIN, PSH, and URG.
5. UDP: UDP probe consists of a single packet that is sent to a closed port. If the
port used on the target system is closed and an ICMP Port Unreachable message
is returned it specifies that there is no Firewall
ipconfig
C:\Windows\System32>ipconfig
Windows IP Configuration
Wireless LAN adapter Local Area Connection* 9:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter Local Area Connection* 10:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : 2405:201:c02b:c802:9aaa:65d9:e33e:4130
Temporary IPv6 Address. . . . . . : 2405:201:c02b:c802:cc11:2ef2:f08a:794d
Link-local IPv6 Address . . . . . : fe80::7fc8:3458:2f48:986e%12
IPv4 Address. . . . . . . . . . . : 192.168.29.227
2
55
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : fe80::8ea3:99ff:fe3b:294f%12
92.168.29.1
Step 2:OSDetection
C:\Windows\System32>nmap -O 192.168.29.227
Starting Nmap 7.94 ( https://nmap.org ) at 2023-11-02 21:32 India Standard Time
Nmap scan report for 192.168.29.227
Host is up (0.0010s latency).
Not shown: 992 closed tcp ports (reset)
PORT STATE SERVICE
7/tcp open echo
9/tcp open discard
13/tcp open daytime
17/tcp open qotd
19/tcp open chargen
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
Device type: general purpose
Running: Microsoft Windows 10
OS CPE: cpe:/o:microsoft:windows_10
OS details: Microsoft Windows 10 1809 - 2004
Network Distance: 0 hops
56
It will only display the chance of Operation System (OS) on the host computer
with the help of Probability and Percentage.
nmap -sV 192.168.29.227 -A
C:\Windows\System32>nmap 127.0.0.1
57
Host is up (0.0012s latency).
Detailed scan
Service scan Timing: About 87.50% done; ETC: 21:40 (0:00:02 remaining)
Service scan Timing: About 87.50% done; ETC: 21:40 (0:00:04 remaining)
Service scan Timing: About 87.50% done; ETC: 21:41 (0:00:06 remaining)
Service scan Timing: About 87.50% done; ETC: 21:42 (0:00:15 remaining)
58
Stats: 0:02:10 elapsed; 0 hosts completed (1 up), 1 undergoing Service Scan
Service scan Timing: About 87.50% done; ETC: 21:42 (0:00:18 remaining)
OS CPE: cpe:/o:microsoft:windows_10
C:\Windows\System32>nmap -O 192.168.29.227-228
59
13/tcp open daytime
OS CPE: cpe:/o:microsoft:windows_10
60