NC-Unique Byte codes for System configuration
NC-Unique Byte codes for System configuration
Implement the data link layer framing methods such as character, character-stuffing, and bit
stuffing.
Bit Stuffing:
#include<stdio.h>
#include<string.h>
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>
strcpy(output, "stx");
j = 3;
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;
}
#include<stdio.h>
#include<string.h>
void main() {
char data[100], frame[100];
char flag[4] = {'f', 'l', 'a', 'g'};
int i, n, j;
n = n + 3;
n++;
for(i = 0; i < 4; i++, n++)
frame[n] = flag[i];
divlen = strlen(div);
datalen = strlen(data);
strcpy(div1, div);
strcpy(rem, temp);
printf("\nQuotient is: ");
for(i = 0; i < datalen; i++) {
printf("%c", quot[i]);
}
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("\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);
// 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;
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("The edges of the minimum cost spanning tree (broadcast tree) are:\n");
if(unionSets(parentU, parentV)) {
printf("Edge %d: (%d, %d) = %d\n", numEdges++, u, v, min);
minCost += min;
}
struct Node {
unsigned dist[20]; // Distance vector
unsigned from[20]; // Route to each node
};
int main() {
int costMatrix[20][20]; // Adjacency matrix representing the network cost (delay)
int numNodes, i, j, k, changes;
return 0;
}
Take a 64-bit plain text and encrypt the same using the DES algorithm
#include <stdio.h>
#include <string.h>
// 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)
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};
printf("\nSecond\tReceived\tSent\tDropped\tRemaining\n");
// 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);
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;
}
return 0;
}
Write a program for frame sorting techniques used in buffers.
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i;
// 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);
}
return 0;
}
How to run N map scan.
#include <stdio.h>
#include <stdlib.h>
int main() {
char target[100];
char command[150];
int choice;
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
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
These utilities are essential for managing network configurations, testing connectivity, diagnosing
issues, and analyzing network traffic.