NAS Practical File Student
NAS Practical File Student
OF
“NETWORKS AND SYSTEMS LAB”
(13450145)
AIM: Learn to use commands like tcpdump, netstat, ipconfig, nslookup and
traceroute. Capture ping and traceroute PDUs using a network protocol
analyzer and examine.
Solution:
1. tcpdump:
Usage: It's commonly used to monitor network activity, diagnose network issues, and
analyze packet contents.
Example: sudo tcpdump icmp captures ICMP (ping) packets and displays them as they
traverse the network.
Output:
2. netstat:
Usage: It's used to monitor network connections, troubleshoot connectivity issues, and
view network statistics.
Example: netstat -tuln displays a list of listening TCP and UDP connections.
Output:
Description: ipconfig (Windows) and ifconfig (Linux) are commands that provide
information about IP configuration and network interfaces.
Usage: They're used to view IP addresses, subnet masks, gateways, and other network
configuration details.
Examples:
Windows: ipconfig /all displays detailed IP configuration information for all
interfaces.
Output:
4. nslookup:
Usage: It's used to look up DNS records, resolve domain names to IP addresses, and
troubleshoot DNS-related issues.
Example: nslookup google.com queries DNS to find the IP address associated with the
domain "google.com".
Output:
5. traceroute:
Description: traceroute is a command-line tool that shows the route and the time taken
for network packets to travel from the source to a destination server.
Usage: It's used to diagnose network routing issues and identify delays or packet loss in
the network path.
Example: traceroute google.com traces the route taken by packets from your computer
to the Google website.
Output:
These commands are essential tools for network administrators, engineers, and anyone dealing
with network troubleshooting and analysis. They provide insights into network activities,
configurations, and issues, helping you better understand and manage your network
environment.
Capturing Ping and Traceroute Packets using Wireshark (Network Protocol Analyzer):
1. Install Wireshark: Download and install Wireshark from its official website.
2. Open Wireshark:
Launch Wireshark and select the network interface you want to capture packets
on.
In the "Capture Filter" field, enter icmp to capture only ICMP packets (ping).
In the "Capture Filter" field, enter icmp to capture only ICMP packets
(traceroute).
In Wireshark, you'll see a list of captured packets. You can click on any packet to
see detailed information.
You can view source and destination IPs, protocols, packet timings, and more.
Remember:
Always consider ethical and legal implications. Obtain proper authorization before
capturing packets on any network.
By using the above commands and Wireshark, you can capture and examine ping and
traceroute packets to better understand how network communication works.
Output:
1) Ping in Wireshark
2) Traceroute in Wireshark
EXPERIMENT NO. 2
AIM: Write a program for a HDLC frame to perform the following. i) Bit stuffing
ii) Character stuffing.
Solution:
#include <stdio.h>
#include <string.h
int consecutive_ones = 0;
int index = 0;
if (input_bits[i] == '1') {
consecutive_ones++;
if (consecutive_ones == max_consecutive_ones) {
stuffed_bits[index++] = '1';
consecutive_ones = 0;
} else {
stuffed_bits[index++] = '1';
} else {
consecutive_ones = 0;
stuffed_bits[index++] = '0';
void characterStuffing(char *input_chars, char start_flag, char end_flag, char escape_char, char
*stuffed_chars) {
int index = 0;
stuffed_chars[index++] = start_flag;
stuffed_chars[index++] = end_flag;
int main() {
int max_consecutive_ones = 5;
char stuffed_bits[100];
char input_chars[] = "ABC$DE#F";
char stuffed_chars[100];
return 0;
Output:
EXPERIMENT NO. 3
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
return min_index;
}
// Function that implements Dijkstra's single-source shortest path algorithm
int dist[V];
bool visited[V];
dist[i] = INT_MAX;
visited[i] = false;
dist[source] = 0;
visited[u] = true;
if (!visited[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] + graph[u][v] < dist[v])
printSolution(dist);
int main() {
int graph[V][V] = {
{0, 4, 0, 0, 0, 0},
{4, 0, 8, 0, 0, 0},
{0, 8, 0, 7, 0, 9},
{0, 0, 7, 0, 1, 0},
{0, 0, 0, 1, 0, 3},
{0, 0, 9, 0, 3, 0}
};
dijkstra(graph, 0);
return 0;
In this implementation:
The graph array represents the weighted adjacency matrix of the graph.
The dijkstra function calculates the shortest path from a given source vertex.
Output:
EXPERIMENT NO. 4
AIM: Write a program for error detecting code using CRC-CCITT.
Solution:
#include <stdio.h>
#include <string.h>
return crc;
}
int main() {
unsigned char data[] = "Hello, CRC-CCITT!"; // Data to be transmitted
int data_len = strlen(data);
return 0;
}
In this program:
The crc_ccitt function calculates the CRC-CCITT checksum for the given data.
The main function simulates the transmission of data, introduces an error by toggling a
bit, and then calculates the received checksum to detect the error.
Output:
EXPERIMENT NO. 5
AIM: Implementation of Stop and Wait Protocol and Sliding Window Protocol.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
if (isFrameLostOrCorrupted(errorProbability)) {
printf("Receiver: Acknowledgment for frame %d lost or corrupted.\n", i);
} else {
printf("Receiver: Acknowledgment for frame %d received.\n", i);
}
printf("\n");
}
}
}
printf("\n");
}
}
int main() {
srand(time(NULL));
float errorProbability = 0.3; // Probability of frame loss or corruption
return 0;
}
Output:
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#define WINDOW_SIZE 3
int base = 1;
int nextSeqNum = 1;
if (isFrameLostOrCorrupted(errorProbability)) {
} else {
nextSeqNum = i + 1;
}
printf("Sender: Waiting for acknowledgments...\n");
base = nextSeqNum;
printf("\n");
int expectedSeqNum = 1;
if (isFrameLostOrCorrupted(errorProbability)) {
} else {
expectedSeqNum++;
printf("\n");
int main() {
srand(time(NULL));
slidingWindowSender(errorProbability);
printf("\n");
slidingWindowReceiver(errorProbability)
return 0;
Output:
EXPERIMENT NO. 6
AIM: Write a program to find the shortest path between vertices using bellman-
ford algorithm.
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
struct Edge {
};
struct Graph {
int V, E;
};
graph->V = V;
graph->E = E;
return graph;
}
int V = graph->V;
int E = graph->E;
int dist[V]
// Initialize distances
dist[i] = INT_MAX;
dist[src] = 0;
int u = graph->edges[j].src;
int v = graph->edges[j].dest;
}
}
int u = graph->edges[i].src;
int v = graph->edges[i].dest;
return;
printDistances(dist, V);
int main() {
graph->edges[0].src = 0;
graph->edges[0].dest = 1;
graph->edges[0].weight = -1;
graph->edges[1].src = 0;
graph->edges[1].dest = 2;
graph->edges[1].weight = 4;
graph->edges[2].src = 1;
graph->edges[2].dest = 2;
graph->edges[2].weight = 3;
graph->edges[3].src = 1;
graph->edges[3].dest = 3;
graph->edges[3].weight = 2;
graph->edges[4].src = 1;
graph->edges[4].dest = 4;
graph->edges[4].weight = 2;
graph->edges[5].src = 3;
graph->edges[5].dest = 2;
graph->edges[5].weight = 5;
graph->edges[6].src = 3;
graph->edges[6].dest = 1;
graph->edges[6].weight = 1;
graph->edges[7].src = 4;
graph->edges[7].dest = 3;
graph->edges[7].weight = -3;
int source = 0
BellmanFord(graph, source);
return 0;
}
In this program:
The Edge structure represents an edge with its source, destination, and weight.
The createGraph function allocates memory for the graph and its edges.
The BellmanFord function computes the shortest paths using the Bellman-Ford
algorithm.
The main function initializes the graph, specifies the source vertex, and invokes the
Bellman-Ford algorithm.
Output:
EXPERIMENT NO. 7
AIM: Implement a program for simple RSA algorithm to encrypt and decrypt the
data.
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
if (b == 0)
return a;
if ((a * x) % m == 1)
return x;
if (exponent % 2 == 1)
exponent /= 2;
return result;
int main() {
int n = p * q; // Calculate n
int e;
if (gcd(e, phi) == 1)
break;
// Encryption: c = (plaintext^e) % n
return 0;
In this program:
An encryption key e is chosen such that it is coprime with phi(n) (GCD is 1).
The decryption key d is calculated using the modular inverse of e modulo phi(n).
Output:
EXPERIMENT NO. 8
AIM: Design a program for congestion control using leaky bucket algorithm.
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
struct LeakyBucket {
int currentSize;
};
bucket->currentSize = 0;
bucket->currentSize += dataSize;
} else {
if (bucket->currentSize > 0) {
bucket->currentSize -= OUTPUT_RATE;
} else {
printf("Bucket is empty.\n");
int main() {
initBucket(&bucket);
addToBucket(&bucket, dataSizes[i]);
outputFromBucket(&bucket);
return 0;
}
In this program:
The outputFromBucket function outputs data from the bucket based on the output
rate.
The main function simulates the arrival of data of different sizes at different times and
applies the leaky bucket algorithm to control the data output rate.
Output:
EXPERIMENT NO. 9
AIM: Develop a program for distance vector algorithm to find suitable path for
transmission.
Solution:
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
#define NUM_NODES 4
if (i == j)
routingTable[i][j] = 0;
else
routingTable[i][j] = INT_MAX;
printf("Routing Table:\n");
for (int i = 0; i < numNodes; i++) {
if (routingTable[i][j] == INT_MAX)
printf("INF ");
else
printf("\n");
routingTable[i][j] = newDist;
}
}
int main() {
int routingTable[NUM_NODES][NUM_NODES];
initRoutingTable(routingTable, numNodes);
routingTable[0][1] = 3;
routingTable[0][2] = 2;
routingTable[1][2] = 1;
routingTable[2][3] = 5;
routingTable[1][3] = 2;
printf("Initial ");
printRoutingTable(routingTable, numNodes);
distanceVector(routingTable, numNodes);
printRoutingTable(routingTable, numNodes);
return 0;
}
In this program:
The initRoutingTable function initializes the routing table with initial values.
The main function initializes the routing table with initial distances, applies the
Distance Vector algorithm, and then prints the updated routing table.
Output:
EXPERIMENT NO. 10
AIM: Develop a program to find the shortest path between vertices using
bellman-ford algorithm.
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
struct Edge {
};
int dist[V];
dist[i] = INT_MAX;
dist[src] = 0;
int u = edgeList[j].src;
int v = edgeList[j].dest;
int u = edgeList[i].src;
int v = edgeList[i].dest;
return;
int main() {
int source = 0;
bellmanFord(edgeList, source);
return 0;
In this program:
The graph array stores the directed edges along with their weights.
The bellmanFord function calculates the shortest path distances using the Bellman-
Ford algorithm.
The main function initializes the graph and source vertex, and then invokes the
Output: