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

NC-Unique Byte codes for System configuration

Computer networks

Uploaded by

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

NC-Unique Byte codes for System configuration

Computer networks

Uploaded by

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

Question:

Implement the data link layer framing methods such as character, character-stuffing, and bit
stuffing.
Bit Stuffing:
#include<stdio.h>
#include<string.h>

void bitStuffing(char *input) {


int n = strlen(input);
char output[100] = "01111110";
int i, j = 8, count = 0;

for (i = 0; i < n; i++) {


output[j++] = input[i];
if (input[i] == '1') {
count++;
if (count == 5) {
output[j++] = '0';
count = 0;
}
} else {
count = 0;
}
}
output[j++] = '0';
output[j++] = '1';
output[j++] = '1';
output[j++] = '11110';

output[j] = '\0';
printf("After bit stuffing the frame is:\n%s\n", output);
}
int main() {
char input[50];
printf("Enter input frame (0's & 1's):\n");
scanf("%s", input);
bitStuffing(input);
return 0;
}

Character Stuffing:
#include<stdio.h>
#include<string.h>

void charStuffing(char *input) {


int i, j = 0, n = strlen(input);
char output[100];
char escapeSeq[] = "dle";

strcpy(output, "stx");
j = 3;

for (i = 0; i < n; i++) {


if (strncmp(&input[i], escapeSeq, 3) == 0) {
strcat(output, "dle");
j += 3;
i += 2;
} else {
output[j++] = input[i];
}
}

strcat(output, "etx");
printf("After character stuffing the frame is:\n%s\n", output);
}

int main() {
char input[50];
printf("Enter input frame:\n");
scanf("%s", input);
charStuffing(input);
return 0;
}

Implement character stuffing with flag

#include<stdio.h>
#include<string.h>

void main() {
char data[100], frame[100];
char flag[4] = {'f', 'l', 'a', 'g'};
int i, n, j;

printf("Enter the input string:\n");


gets(data);
n = strlen(data);

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


frame[i] = flag[i];

for(i = 0, j = 4; i < n; i++, j++) {


if(data[i] == 'f' && data[i + 1] == 'l' && data[i + 2] == 'a' && data[i + 3] == 'g') {
frame[j] = 'e';
j++;
frame[j] = 's';
j++;
frame[j] = 'c';
j++;
n = n + 3;
} else if(data[i] == 'e' && data[i + 1] == 's' && data[i + 2] == 'c') {
frame[j] = 'e';
j++;
frame[j] = 's';
j++;
frame[j] = 'c';
j++;
n = n + 3;
}
frame[j] = data[i];
}

n = n + 3;
n++;
for(i = 0; i < 4; i++, n++)
frame[n] = flag[i];

printf("String after stuffing is:\n");


puts(frame);
}
Write a program to compute CRC code for the polynomials CRC-12, CRC-16, and CRCCCIP
#include<stdio.h>
#include<string.h>

void computeCRC(char *data, char *div) {


int i, j, divlen, datalen;
char temp[30], quot[100], rem[30], div1[30];

divlen = strlen(div);
datalen = strlen(data);

strcpy(div1, div);

for(i = 0; i < divlen - 1; i++) {


data[datalen + i] = '0';
}

for(i = 0; i < divlen; i++) {


temp[i] = data[i];
}

for(i = 0; i < datalen; i++) {


quot[i] = temp[0];
if(quot[i] == '0') {
for(j = 0; j < divlen; j++) {
div[j] = '0';
}
} else {
for(j = 0; j < divlen; j++) {
div[j] = div1[j];
}
}
for(j = divlen - 1; j > 0; j--) {
if(temp[j] == div[j]) {
rem[j - 1] = '0';
} else {
rem[j - 1] = '1';
}
}
rem[divlen - 1] = data[i + divlen];
strcpy(temp, rem);
}

strcpy(rem, temp);
printf("\nQuotient is: ");
for(i = 0; i < datalen; i++) {
printf("%c", quot[i]);
}

printf("\nRemainder is: ");


for(i = 0; i < divlen - 1; i++) {
printf("%c", rem[i]);
}

printf("\nFinal data is: ");


for(i = 0; i < datalen; i++) {
printf("%c", data[i]);
}

for(i = 0; i < divlen - 1; i++) {


printf("%c", rem[i]);
}
}
int main() {
char data[100], div[30];

printf("Enter data: ");


gets(data);

printf("Enter CRC-12 divisor: ");


gets(div);
computeCRC(data, div);

printf("\nEnter CRC-16 divisor: ");


gets(div);
computeCRC(data, div);

printf("\nEnter CRC-32 divisor (CRCCCIP): ");


gets(div);
computeCRC(data, div);

return 0;
}
Develop a simple data link layer that performs flow control using the sliding window protocol, and
loss recovery using the Go-Back-N mechanism

#include<stdio.h>

int main() {
int w, i, f, frames[50], ack[50];

printf("Enter window size: ");


scanf("%d", &w);

printf("\nEnter number of frames to transmit: ");


scanf("%d", &f);

printf("\nEnter %d frames: ", f);


for(i = 1; i <= f; i++) {
scanf("%d", &frames[i]);
}

printf("\nWith sliding window protocol the frames will be sent in the following manner:\n\n");
printf("After sending %d frames at each stage, sender waits for acknowledgement sent by the
receiver.\n\n", w);

// Sliding window protocol


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]);
}
}
// For remaining frames, acknowledging them at the end
if(f % w != 0) {
printf("\nAcknowledgement of above frames sent is received by sender\n");
}

// Go-Back-N mechanism
printf("\nGo-Back-N Recovery Mechanism:\n");
printf("If any frame is lost or corrupted, all frames after that one will need to be retransmitted.\n");

return 0;
}
Implement Dijkstra’s algorithm to compute the shortest path through a network.
#include<stdio.h>

void main() {
int n, p, cost[10][10], path[10][10], t[10], min_cost, min_path;

printf("Enter number of vertices: ");


scanf("%d", &n);

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


for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
scanf("%d", &cost[i][j]);
}
}

printf("Enter the number of paths: ");


scanf("%d", &p);

printf("Enter the possible paths:\n");


for(int i = 1; i <= p; i++) {
for(int j = 1; j <= n; j++) {
scanf("%d", &path[i][j]);
}
}

// Calculate total cost for each path


for(int i = 1; i <= p; i++) {
t[i] = 0;
int current = 1; // starting point
for(int j = 1; j <= n; j++) {
int next = path[i][j + 1];
t[i] += cost[current][next];
if(next == n) break;
current = next;
}
}

// Find minimum cost and corresponding path


min_cost = t[1];
min_path = 1;
for(int i = 2; i <= p; i++) {
if(t[i] < min_cost) {
min_cost = t[i];
min_path = i;
}
}

// Output minimum cost and path


printf("Minimum cost: %d\n", min_cost);
printf("Minimum cost path: ");
for(int i = 1; i <= n; i++) {
printf("-->%d", path[min_path][i]);
}
printf("\n");
}
Take an example of subnet pose to obtain a broadcast tree using Kruskal’s algorithm
#include<stdio.h>
#include<stdlib.h>

int parent[9];
int cost[9][9];
int numVertices, numEdges = 1, minCost = 0;

int findParent(int);
int unionSets(int, int);

void main() {
int i, j, min, u, v, edgeWeight;

printf("Enter the number of vertices: ");


scanf("%d", &numVertices);

printf("Enter the cost adjacency matrix:\n");


for(i = 1; i <= numVertices; i++) {
for(j = 1; j <= numVertices; j++) {
scanf("%d", &cost[i][j]);
if(cost[i][j] == 0)
cost[i][j] = 99; // Set high value for no connection
}
}

printf("The edges of the minimum cost spanning tree (broadcast tree) are:\n");

while(numEdges < numVertices) {


min = 99;

for(i = 1; i <= numVertices; i++) {


for(j = 1; j <= numVertices; j++) {
if(cost[i][j] < min) {
min = cost[i][j];
u = i;
v = j;
}
}
}

int parentU = findParent(u);


int parentV = findParent(v);

if(unionSets(parentU, parentV)) {
printf("Edge %d: (%d, %d) = %d\n", numEdges++, u, v, min);
minCost += min;
}

cost[u][v] = cost[v][u] = 99; // Mark the edge as visited


}

printf("\nMinimum cost = %d\n", minCost);


}

int findParent(int vertex) {


while(parent[vertex]) {
vertex = parent[vertex];
}
return vertex;
}

int unionSets(int parentU, int parentV) {


if(parentU != parentV) {
parent[parentV] = parentU;
return 1; // Union successful
}
return 0; // Union not possible (same parent)
}
Take a subnet graph with weights indicating delay between node and update the routing table at
each node using distance vector routing algorithm
#include<stdio.h>

struct Node {
unsigned dist[20]; // Distance vector
unsigned from[20]; // Route to each node
};

struct Node routingTable[10]; // Array of routing tables for each node

int main() {
int costMatrix[20][20]; // Adjacency matrix representing the network cost (delay)
int numNodes, i, j, k, changes;

// Input number of nodes


printf("Enter the number of nodes: ");
scanf("%d", &numNodes);

// Input cost matrix (delay between nodes)


printf("Enter the cost matrix (use 0 for no delay between same node):\n");
for(i = 0; i < numNodes; i++) {
for(j = 0; j < numNodes; j++) {
scanf("%d", &costMatrix[i][j]);
if(i == j) costMatrix[i][j] = 0; // No delay to self
routingTable[i].dist[j] = costMatrix[i][j]; // Initialize distance
routingTable[i].from[j] = j; // Route to self is direct
}
}

// Apply Distance Vector Routing algorithm


do {
changes = 0;
// Iterate over all nodes to update routing tables
for(i = 0; i < numNodes; i++) {
for(j = 0; j < numNodes; j++) {
for(k = 0; k < numNodes; k++) {
// Check if a shorter path exists through another node
if(routingTable[i].dist[j] > costMatrix[i][k] + routingTable[k].dist[j]) {
routingTable[i].dist[j] = costMatrix[i][k] + routingTable[k].dist[j];
routingTable[i].from[j] = k; // Update next hop
changes++;
}
}
}
}
} while(changes != 0); // Repeat until no more changes occur

// Output the final routing table for each node


for(i = 0; i < numNodes; i++) {
printf("\nRouting table for node %d:\n", i + 1);
for(j = 0; j < numNodes; j++) {
printf("To node %d via node %d: Distance = %d\n", j + 1, routingTable[i].from[j] + 1,
routingTable[i].dist[j]);
}
}

return 0;
}
Take a 64-bit plain text and encrypt the same using the DES algorithm
#include <stdio.h>
#include <string.h>

#define BLOCK_SIZE 8 // 64-bit block

void encrypt_decrypt_XOR(char *input, const char *key, char *output) {


int len = strlen(input);
int key_len = strlen(key);

// XOR each character of input with the corresponding character of the key
for (int i = 0; i < len; i++) {
output[i] = input[i] ^ key[i % key_len]; // Cycle through key
}
output[len] = '\0'; // Null-terminate the output string
}

int main() {
char plain_text[BLOCK_SIZE + 1]; // Store 64-bit plain text (8 characters)
char encrypted_text[BLOCK_SIZE + 1];
char decrypted_text[BLOCK_SIZE + 1];
char key[BLOCK_SIZE + 1]; // Store 64-bit key (8 characters)

// Prompt user for input


printf("Enter plain text (8 characters): ");
fgets(plain_text, sizeof(plain_text), stdin);
plain_text[strcspn(plain_text, "\n")] = '\0'; // Remove newline character

printf("Enter 8-character key: ");


fgets(key, sizeof(key), stdin);
key[strcspn(key, "\n")] = '\0'; // Remove newline character
// Encrypt the plain text
encrypt_decrypt_XOR(plain_text, key, encrypted_text);
printf("Encrypted text: ");
for (int i = 0; encrypted_text[i] != '\0'; i++) {
printf("%02X ", (unsigned char)encrypted_text[i]); // Display in hex
}
printf("\n");

// Decrypt the encrypted text


encrypt_decrypt_XOR(encrypted_text, key, decrypted_text);
printf("Decrypted text: %s\n", decrypted_text);

return 0;
}
Write a program for congestion control using Leaky bucket algorithm

#include <stdio.h>
#include <stdlib.h>

#define MIN(x, y) ((x) > (y) ? (y) : (x)) // Helper macro to get minimum of x and y

int main() {
int output_rate, drop = 0, capacity, current_bucket = 0, packets_received, i = 0, seconds, ch;
int packet_arrival[10] = {0};

// Input the bucket size (capacity) and the output rate


printf("\nEnter Bucket Size: ");
scanf("%d", &capacity);
printf("\nEnter Output Rate: ");
scanf("%d", &output_rate);

// Input packet arrival rates for each second


do {
printf("\nEnter number of packets arriving at second %d: ", i + 1);
scanf("%d", &packet_arrival[i]);
i++;
printf("\nEnter 1 to continue or 0 to quit: ");
scanf("%d", &ch);
} while (ch);

seconds = i; // Number of seconds input

printf("\nSecond\tReceived\tSent\tDropped\tRemaining\n");

// Process each second and update the bucket's state


for (i = 0; i < seconds; i++) {
printf("%d", i + 1); // Display the second

// Received packets in this second


printf("\t%d\t", packet_arrival[i]);

// Sent packets: minimum of (received packets + current bucket) and output rate
int sent_packets = MIN(packet_arrival[i] + current_bucket, output_rate);
printf("\t%d\t", sent_packets);

// Calculate the new number of packets in the bucket


int excess_packets = packet_arrival[i] + current_bucket - output_rate;

if (excess_packets > 0) {
if (excess_packets > capacity) {
current_bucket = capacity; // Bucket overflows, fill it to capacity
drop = excess_packets - capacity; // Excess packets are dropped
} else {
current_bucket = excess_packets; // No overflow, but the bucket is filled
drop = 0;
}
} else {
current_bucket = 0; // No excess packets, bucket is empty
drop = 0;
}

// Display the results for this second


printf("\t%d\t%d\n", drop, current_bucket);
}

return 0;
}
Write a program for frame sorting techniques used in buffers.

#include <stdio.h>
#include <stdlib.h>

// Define a structure for a Frame


typedef struct Frame {
int seq_num; // Sequence number of the frame
char data[100]; // Data of the frame
};

// Function to sort frames based on their sequence number


void sort_frames(Frame frames[], int n) {
int i, j;
Frame temp;
// Bubble sort algorithm to sort frames by sequence number
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (frames[i].seq_num > frames[j].seq_num) {
// Swap frames[i] and frames[j]
temp = frames[i];
frames[i] = frames[j];
frames[j] = temp;
}
}
}
}

int main() {
int n, i;

// Input the number of frames


printf("Enter the number of frames: ");
scanf("%d", &n);

// Allocate memory for the frames


Frame *frames = (Frame *)malloc(n * sizeof(Frame));

// Input frames
for (i = 0; i < n; i++) {
printf("Enter sequence number and data for frame %d: ", i + 1);
scanf("%d %s", &frames[i].seq_num, frames[i].data);
}

// Sort the frames by sequence number


sort_frames(frames, n);

// Print sorted frames


printf("\nFrames after sorting by sequence number:\n");
printf("Seq Num\tData\n");
for (i = 0; i < n; i++) {
printf("%d\t%s\n", frames[i].seq_num, frames[i].data);
}

// Free the allocated memory


free(frames);

return 0;
}
How to run N map scan.
#include <stdio.h>
#include <stdlib.h>

int main() {
char target[100];
char command[150];
int choice;

// Prompt the user for the target IP address or domain


printf("Enter the target IP address or domain: ");
scanf("%s", target);

// Prompt the user to select the scan type


printf("Choose the type of Nmap scan you want to run:\n");
printf("1. Quick scan (-T4 -F)\n");
printf("2. Full scan (no extra options)\n");
printf("3. Scan for open ports only (-p-)\n");
printf("4. OS detection (-O)\n");
printf("5. Aggressive scan (-A)\n");
printf("Enter your choice (1-5): ");
scanf("%d", &choice);

// Construct the Nmap command based on user choice


switch(choice) {
case 1:
sprintf(command, "nmap -T4 -F %s", target);
break;
case 2:
sprintf(command, "nmap %s", target);
break;
case 3:
sprintf(command, "nmap -p- %s", target);
break;
case 4:
sprintf(command, "nmap -O %s", target);
break;
case 5:
sprintf(command, "nmap -A %s", target);
break;
default:
printf("Invalid choice. Exiting.\n");
return 1;
}

// Print the constructed Nmap command


printf("Running the following Nmap command:\n%s\n", command);

// Execute the Nmap command


int status = system(command);
if (status == -1) {
printf("Failed to execute Nmap command.\n");
return 1;
} else {
printf("Nmap scan completed.\n");
}

return 0;
}
11. Operating System Detection using N map.

To perform an Operating System (OS) detection scan using Nmap, there are several options and
strategies depending on the level of detail and accuracy you need. Below are the common Nmap
commands and options for OS detection:
1. Basic OS Detection:
The basic Nmap command for OS detection is:
bash
Copy code
nmap -O <target>
• -O: This flag tells Nmap to attempt to detect the operating system of the target device.
• <target>: Replace this with the IP address or domain name of the target device.
Example:
bash
Copy code
nmap -O 192.168.1.1
This will perform an OS scan and provide you with the best guess of the target's operating system.
2. Aggressive OS and Application Detection:
To get more details about the target, such as OS version and application versions, you can use the -A
flag:
bash
Copy code
nmap -A -T4 <target>
• -A: Enables aggressive scan, which includes OS detection (-O), application version detection,
and script scanning.
• -T4: Sets the timing template to 4, which makes the scan faster by increasing the number of
probes sent.
Example:
bash
Copy code
nmap -A -T4 192.168.1.1
This command provides detailed information about the target, including OS version, open ports,
service versions, and more.
3. Disable Ping Scan:
Some firewalls and servers may block ICMP ping scans, which are used by Nmap to check if a target is
alive. You can disable this by using the -Pn flag, which assumes the target is up:
bash
Copy code
nmap -O -Pn <target>
• -Pn: Disables the ping scan, meaning Nmap will skip the host discovery phase and directly
proceed to scan the target.
Example:
bash
Copy code
nmap -O -Pn 192.168.1.1
You can also combine the -Pn with the aggressive scan options for a more detailed scan that doesn't
rely on pinging:
bash
Copy code
nmap -Pn -A -T4 <target>
4. Using Version Detection to Confirm OS:
Sometimes, basic OS detection may be inconclusive. To get additional information, you can run an
aggressive scan that includes application version detection:
bash
Copy code
nmap -A -T4 <target>
For example, the version of OpenSSH could indicate the OS is Ubuntu, especially if the version is listed
as something like 2ubuntu2.13.
5. Evasion Techniques:
If you are scanning a target with firewalls that block common scan techniques, you might need to
employ evasive techniques:
bash
Copy code
nmap -O -T1 <target>
• -T1: Use a more stealthy (slow) scan to avoid detection, though it will take longer.
Or you can try using different scan types, like SYN scan (-sS), to bypass some firewalls:
bash
Copy code
nmap -O -sS -T4 <target>
Example of Full Command:
To scan a target, disable the ping scan, detect the OS, and perform an aggressive scan for applications
and services:
bash
Copy code
nmap -Pn -A -T4 192.168.1.1
Conclusion:
Nmap provides various ways to detect the operating system of a target. The most basic scan is done
with the -O option, but for more detailed results, using the aggressive scan (-A) with application
version detection is often useful. You can also disable pinging using -Pn if firewalls block ICMP packets.
Study of basic Network configuration commands and utilities to debug the network issues.
1. IP Configuration and Information
• ipconfig (Windows): Displays the current network configuration for all network adapters, such
as IP addresses, subnet masks, default gateways, and DNS servers.
o ipconfig /all: Displays detailed information for all network adapters, including MAC
addresses, DNS servers, and DHCP lease information.
o ipconfig /release: Releases the current DHCP configuration (IP address) from the
system, useful when troubleshooting IP assignment.
o ipconfig /renew: Renews the IP address by requesting a new one from the DHCP
server.
Example:
bash
Copy code
ipconfig /all
Output:
yaml
Copy code
Windows IP Configuration
Host Name . . . . . . . . . . . . : MyComputer
Primary DNS Suffix . . . . . . . : local
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Ethernet:


Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) Ethernet Connection (2) I219-V
Physical Address. . . . . . . . . : XX-XX-XX-XX-XX-XX
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.1.101(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
• ifconfig (Linux/macOS): The legacy tool used to configure, display, and control network
interfaces.
o ifconfig: Displays the status of all active network interfaces.
o ifconfig eth0 down: Disables the network interface (eth0).
o ifconfig eth0 up: Enables the network interface (eth0).
Example:
bash
Copy code
ifconfig
Output:
arduino
Copy code
eth0 Link encap:Ethernet HWaddr 00:0c:29:9b:47:88
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9b:4788/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3924914 errors:0 dropped:0 overruns:0 frame:0
TX packets:2398839 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3207971860 (3.2 GB) TX bytes:1485593437 (1.4 GB)
• ip (Linux): A more powerful and flexible replacement for ifconfig in modern Linux distributions.
It allows you to show and manipulate routing, devices, and tunnels.
o ip a: Shows all interfaces with IP addresses.
o ip link set eth0 up: Activates the eth0 interface.
o ip link set eth0 down: Deactivates the eth0 interface.
Example:
bash
Copy code
ip a
Output:
yaml
Copy code
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever

2. Check Network Connectivity


• ping: Sends an ICMP echo request to a host and waits for a reply, testing connectivity.
o ping google.com: Pings Google's server to check if it’s reachable.
o ping -c 4 8.8.8.8: Sends 4 pings to Google's DNS server (8.8.8.8).
Example:
bash
Copy code
ping google.com
Output:
python
Copy code
PING google.com (142.250.180.78) 56(84) bytes of data.
64 bytes from 142.250.180.78: icmp_seq=1 ttl=115 time=14.9 ms
64 bytes from 142.250.180.78: icmp_seq=2 ttl=115 time=14.7 ms
• traceroute (Linux/macOS) / tracert (Windows): Traces the path packets take to a destination
by showing each hop in the network.
o traceroute google.com (Linux/macOS)
o tracert google.com (Windows)
Example:
bash
Copy code
traceroute google.com
Output:
scss
Copy code
traceroute to google.com (142.250.180.78), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 1.180 ms 1.350 ms 1.504 ms
2 10.0.0.1 (10.0.0.1) 15.210 ms 15.274 ms 15.403 ms
3 ***
4 142.250.180.78 (142.250.180.78) 15.820 ms 16.021 ms 16.378 ms
3. View and Manipulate Routing Tables
• route: Displays or modifies the network routing table, which shows the paths used by the
system to reach different network destinations.
o route print: Shows the routing table (Windows).
o route -n: Displays the routing table in numeric format (Linux).
Example:
bash
Copy code
route print
Output (Windows):
markdown
Copy code
===========================================================================
Interface List
15...00 15 5d 32 44 b9 ......Ethernet
13...00 15 5d 51 a1 c0 ......Wi-Fi
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.101 25
• ip route (Linux): This command is used to view or modify the IP routing table.
o ip route show: Displays the current routing table.
o ip route add default via 192.168.1.1: Adds a default route via the specified gateway.
Example:
bash
Copy code
ip route show
Output:
sql
Copy code
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 scope link

4. DNS Utilities
• nslookup: A command-line tool to query DNS servers for domain name information.
o nslookup google.com: Resolves the IP address for google.com.
Example:
bash
Copy code
nslookup google.com
Output:
yaml
Copy code
Server: UnKnown
Address: 192.168.1.1

Non-authoritative answer:
Name: google.com
Addresses: 142.250.180.78
142.250.180.102
• dig (Linux/macOS): A more advanced tool for querying DNS and providing detailed
information.
o dig google.com: Returns DNS information for google.com.
o dig google.com +trace: Traces the entire DNS resolution path.
Example:
bash
Copy code
dig google.com
Output:
yaml
Copy code
; <<>> DiG 9.16.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61622
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 300 IN A 142.250.180.78

5. Network Statistics
• netstat: Displays network connections, routing tables, interface statistics, and more.
o netstat -a: Displays all active connections.
o netstat -r: Displays the routing table.
o netstat -an | grep LISTEN: Displays listening ports (Linux).
Example:
bash
Copy code
netstat -a
Output:
css
Copy code
Active Connections

Proto Local Address Foreign Address State


TCP 192.168.1.101:139 0.0.0.0:0 LISTENING
TCP 192.168.1.101:80 0.0.0.0:0 LISTENING

6. Diagnosing ARP Issues


• arp: Displays or modifies the system's ARP cache, which stores mappings of IP addresses to
MAC addresses.
o arp -a: Shows the ARP table (Windows).
o arp -n: Shows the ARP table (Linux).
o arp -d 192.168.1.1: Deletes a specific ARP entry.
Example:
bash
Copy code
arp -a
Output:
sql
Copy code
Interface: 192.168.1.101 --- 0x1
Internet Address Physical Address Type
192.168.1.1 00-15-5d-51-a1-c0 dynamic

7. Bandwidth and Packet Analysis


• tcpdump (Linux/macOS): A network packet analyzer that captures network traffic.
o tcpdump -i eth0: Captures all packets on the eth0 interface.
o tcpdump -c 10 -i eth0: Captures only 10 packets.
o tcpdump -nn: Avoids DNS resolution for hostnames.
Example:
bash
Copy code
tcpdump -i eth0
Output:
yaml
Copy code
20:54:45.698817 IP 192.168.1.101.80 > 192.168.1.1.12345: Flags [P.], seq 1812:1844, ack 12345, win
16384, length 32
• Wireshark: A graphical network packet analyzer, more advanced than tcpdump, with an
intuitive interface for packet analysis.

8. Network Service Testing


• telnet: Connects to remote systems to test specific services (e.g., HTTP on port 80).
o telnet google.com 80: Tests connectivity to port 80 on google.com.
Example:
bash
Copy code
telnet google.com 80
Output:
sql
Copy code
Trying 142.250.180.78...
Connected to google.com.
Escape character is '^]'.
• curl: A tool to interact with HTTP services and fetch data from URLs.
o curl -I http://example.com: Fetches HTTP headers from a webpage.
o curl http://example.com: Fetches the full content of a webpage.
Example:
bash
Copy code
curl -I http://google.com
Output:
yaml
Copy code
HTTP/1.1 200 OK
Date: Tue, 25 May 2024 10:00:00 GMT
Server: gws
• netcat (nc): A versatile tool to read and write data over network connections.
o nc -zv 192.168.1.1 22: Checks if port 22 (SSH) is open on a remote host.
Example:
bash
Copy code
nc -zv 192.168.1.1 22
Output:
css
Copy code
Connection to 192.168.1.1 22 port [tcp/ssh] succeeded!

These utilities are essential for managing network configurations, testing connectivity, diagnosing
issues, and analyzing network traffic.

You might also like