0% found this document useful (0 votes)
14 views18 pages

Network Commands and Bit Stuffing Example

Dutch

Uploaded by

rolex dilli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views18 pages

Network Commands and Bit Stuffing Example

Dutch

Uploaded by

rolex dilli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Explore and implement some of the most commonly used network commands available in the

Windows operating system.

1. ipconfig
Description: Displays the IP configuration of the computer’s network interfaces, including IP
address, subnet mask, and default gateway.
Usage: ipconfig
2. ipconfig /all
Description: Provides detailed information about all network interfaces, including MAC
addresses, DHCP settings, and more.
Usage: ipconfig /all
3. ping
Description: Tests connectivity between your computer and a remote host by sending ICMP
Echo Request packets and measuring the response time.
Usage: ping <hostname or IP address>
4. tracert
Description: Traces the route taken by packets to reach a destination host, showing each hop
along the way and the time taken.
Usage: tracert <hostname or IP address>
5. netstat
Description: Displays active network connections, listening ports, and network statistics.
Usage: netstat
6. netstat -an
Description: Shows all active connections and listening ports with numerical addresses and
port numbers.
Usage: netstat -an
7. nslookup
Description: Queries DNS servers to obtain domain name or IP address information.
Usage: nslookup <hostname or IP address>
8. arp -a
Description: Displays the Address Resolution Protocol (ARP) cache, showing IP-to-MAC
address mappings.
Usage: arp -a
9. route print
Description: Displays the current routing table, which shows how packets are routed on the
network.
Usage: route print
10. netsh
Description: A versatile command-line tool for managing network configurations, including
network interfaces, firewall settings, and more.
Usage: netsh followed by specific commands (e.g., netsh wlan show profiles to view wireless
profiles).

The pathping command combines the functionality of ping and tracert (traceroute), providing detailed
information about the path packets take to a destination and the quality of the network along that path.
It is useful for diagnosing network issues by offering insights into packet loss and latency at each hop.

11. pathping
Purpose: Analyzes the path packets take to reach a destination and provides information about
packet loss and latency at each hop.
How It Works:
Performs a trace of the route to the destination similar to tracert.
Then, sends multiple pings to each hop to measure packet loss and latency more accurately.
Combines the results to provide a detailed report.
Information Provided:
List of hops along the route.
Round-trip times to each hop.
Packet loss percentage at each hop.
Overall packet loss and latency statistics.
Usage: Useful for identifying where packet loss or high latency is occurring along the path to a
destination.
The pathping and tracert commands are both used for diagnosing network issues, but they offer
different levels of detail and serve slightly different purposes:

tracert
• Purpose: Traces the route packets take from your computer to a destination, showing each hop
(intermediate router) along the way.
• Functionality:
o Sends ICMP Echo Request packets with incrementally increasing TTL (Time To Live)
values.
o Each router or hop along the path decreases the TTL by 1. When the TTL reaches 0, the
router sends back an ICMP Time Exceeded message, allowing tracert to identify the
hop.
• Information Provided:
o The sequence of routers or hops between your computer and the destination.
o Round-trip time for packets to each hop.
o IP addresses of intermediate devices.
• Usage: Useful for understanding the path taken by packets to reach a destination and
identifying where delays or routing issues may be occurring.
• Example Output
Tracing route to [Link] [[Link]]
over a maximum of 30 hops:

1 <1 ms <1 ms <1 ms [Link] [[Link]]


2 5 ms 4 ms 5 ms [Link]
3 10 ms 11 ms 10 ms [Link]
4 12 ms 13 ms 12 ms [Link]

Trace complete.
pathping
• Purpose: Combines the functionality of tracert and ping to provide detailed information about
the path packets take to a destination and the quality of the network along that path.
• Functionality:
o Performs a trace of the route similar to tracert.
o Sends multiple pings to each hop along the route to measure packet loss and latency
more accurately.
o Provides a detailed report that combines route information with network performance
statistics.
• Information Provided:
o List of hops along the route.
o Round-trip times to each hop.
o Packet loss percentage at each hop.
o Overall packet loss and latency statistics.
• Usage: Useful for diagnosing issues related to packet loss and latency at specific points along
the path, providing a more comprehensive view of network performance.
• Example Output
Tracing route to [Link] [[Link]]
over a maximum of 30 hops:

0 [Link] [[Link]]
1 [Link]
2 [Link]
3 [Link]
4 [Link]

Computing statistics for 300 seconds...

Destination: [Link] [[Link]]

Hop RTT (ms) Packet Loss %


1 1 0%
2 5 0%
3 10 0%
4 12 0%

Trace complete.
Summary of Differences
• Detail Level:
o tracert: Provides a basic route trace with round-trip times to each hop.
o pathping: Offers a detailed analysis of the route with packet loss and latency statistics at
each hop.
• Purpose:
o tracert: Identifies the route taken by packets and where delays occur.
o pathping: Provides a deeper analysis of network performance, including packet loss and
latency issues.
• Usage:
o Use tracert for a quick overview of the route and intermediate hops.
o Use pathping for a comprehensive analysis of network quality and performance issues
along the route.
Implement a system where the client sends binary data to the server using bit stuffing, and the
server removes the stuffed bits to retrieve the original data. The client connects to the server over
a socket and sends the bit-stuffed data. The server receives the stuffed data, unpacks it by
removing the stuffed bits, and then displays the original unstuffed data.

[Link]:

import [Link].*;
import [Link].*;
import [Link];
public class BitSender {
public static void main(String[] args) throws IOException
{
// Opens a socket for connection
Socket socket = new Socket("localhost", 6789);
DataInputStream dis = new DataInputStream([Link]());
DataOutputStream dos = new DataOutputStream([Link]());
// Scanner class object to take input
Scanner sc = new Scanner([Link]);
// Takes input of unstuffed data from user
[Link]("Enter data: ");
String data = [Link]();
int cnt = 0;
String s = "";
for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);
if (ch == '1') {
// count number of consecutive 1's
// in user's data
cnt++;
if (cnt < 5)
s += ch;
else {
// add one '0' after 5 consecutive 1's
s = s + ch + '0';
cnt = 0;
}
}
else {
s += ch;
cnt = 0;
}
}
// add flag byte in the beginning
// and end of stuffed data
s = "01111110" + s + "01111110";
[Link]("Data stuffed in client: " + s);
[Link]("Sending to server for unstuffing");
[Link](s);
}
}

[Link]:

import [Link].*;
import [Link].*;
public class BitReceiver {
public static void main(String[] args) throws IOException
{
ServerSocket skt = new ServerSocket(6789);
// Used to block until a client connects to the server
Socket socket = [Link]();
DataInputStream dis = new DataInputStream([Link]());
DataOutputStream dos = new DataOutputStream([Link]());
// Receiving the string from the client which
// needs to be stuffed
String s = [Link]();
[Link]("Stuffed data from client: " + s);
[Link]("Unstuffed data: ");
int cnt = 0;
// removal of stuffed bits:
// start from 9th bit because the first 8
// bits are of the special pattern.
for (int i = 8; i < [Link]() - 8; i++) {
char ch = [Link](i);
if (ch == '1') {
cnt++;
[Link](ch);
// After 5 consecutive 1's one stuffed bit
//'0' is added. We need to remove that.
if (cnt == 5) {
i++;
cnt = 0;
}
}
else {
// print unstuffed data
[Link](ch);
// we only need to maintain count
// of consecutive 1's
cnt = 0;
}
}
[Link]();
}
}

Output:
[Link] :

Enter data:
0110111111011
Data stuffed in client :
011111100110111110101101111110
Sending to server for unstuffing

[Link]:

Stuffed data from client :


011111100110111110101101111110
Unstuffed data:
0110111111011
Implement a client-server system where the client sends a message to the server using byte
stuffing, and the server removes the stuffed bytes to retrieve the original message. The client
connects to the server over a socket and sends the byte-stuffed message. The server receives the
stuffed message, unpacks it by removing the stuffed bytes, and displays the original message.

[Link]:

import [Link].*;
import [Link].*;
import [Link].*;

public class ByteSender{


public static void main(String args[]) throws IOException
{
InetAddress ip = [Link]();
int port = 8888;
Scanner sc = new Scanner([Link]);
// Opens a socket for connection
Socket s = new Socket(ip, port);
// Declaring I/O Streams
DataInputStream dis = new DataInputStream([Link]());
DataOutputStream dos = new DataOutputStream([Link]());
while (true) {
[Link]("Enter the Message to be Sent : ");
String data = [Link]();
String res = new String()
// Data in each frame is stuffed by 'F' at beginning and end
data = 'F' + data + 'F';
for (int i = 0; i < [Link](); i++) {
// Stuff with 'E' if 'F' is found in the data to be sent
if ([Link](i) == 'F' && i != 0 && i != ([Link]() - 1))
res = res + 'E' + [Link](i)
// Stuff with 'E' if 'E' is found in the data to be sent
else if ([Link](i) == 'E')
res = res + 'E' + [Link](i);
else
res = res + [Link](i);
}
[Link]("The data being sent (with byte stuffed) is : " + res);
// Send the data to the receiver
[Link](res);
[Link]("Seding Message....");
if ([Link]().equals("success"))
[Link]("Thanks for the Feedback Server!!");
// End Messaging
[Link]("bye");
break;
}
// Close all connections
[Link]();
[Link]();
[Link]();
}
}

[Link]:

import [Link].*;
import [Link].*;

public class ByteReceiver {


public static void main(String[] args) throws IOException {
// Opens a socket for connection
ServerSocket serverSocket = new ServerSocket(8888);
[Link]("Waiting for the client to connect...");
Socket socket = [Link]();
// Declaring I/O Streams
DataInputStream dis = new DataInputStream([Link]());
while (true) {
// Read the stuffed data from the sender
String stuffedData = [Link]();
[Link]("Received Stuffed Data: " + stuffedData);
String destuffedData = "";
char delimiter = 'F';
char escape = 'E';
boolean escapeNext = false;
// Unstuff the data
for (int i = 1; i < [Link]() - 1; i++) {
char ch = [Link](i);
if (escapeNext) {
destuffedData += ch;
escapeNext = false;
} else if (ch == escape) {
escapeNext = true;
} else {
destuffedData += ch;
}
}
[Link]("The Destuffed Message is: " + destuffedData);
// Ask if the sender wants to send another message
[Link]("Waiting for the next message...");
}
// Close the connection
// (not reached in this example, but would be in a real-world application)
}
}

Output :
[Link]:
Enter the message to be sent :
FEEL
The data being sent (with byte stuffed) is : FEFEEEELF
Sending Message...

[Link]:
Waiting for the client to connect...
Received stuffed data : FEFEEEELF
The Destuffed Message is : FEEL
Waiting for the next message ...
Implement a Cyclic Redundancy Check (CRC) mechanism in Java. The CRC method helps
detect errors in data transmission. Your program will simulate both the sender and the receiver
sides of CRC by generating a CRC code at the sender side and verifying the received data at the
receiver side.

import [Link];

class CRC {
public static void main(String args[]) {
Scanner scan = new Scanner([Link]);
// Accept the input data bits
[Link]("Enter the size of the data:");
int dataSize = [Link]();
int data[] = new int[dataSize];
[Link]("Enter the data bits (0 or 1):");
for (int i = 0; i < dataSize; i++) {
[Link]("Enter bit number " + (i + 1) + ": ");
data[i] = [Link]();
}
// Accept the divisor bits
[Link]("Enter the size of the divisor:");
int divisorSize = [Link]();
int divisor[] = new int[divisorSize];
[Link]("Enter the divisor bits (0 or 1):");
for (int i = 0; i < divisorSize; i++) {
[Link]("Enter bit number " + (i + 1) + ": ");
divisor[i] = [Link]();
}
// Perform division to get the remainder
int[] remainder = divide(data, divisor);
// Display the CRC code (data + remainder)
[Link]("\nThe CRC code generated is:");
for (int i = 0; i < [Link]; i++) {
[Link](data[i]);
}
for (int i = 0; i < [Link] - 1; i++) {
[Link](remainder[i]);
}
[Link]();
// Accept the sent data (data + CRC code)
int[] sentData = new int[[Link] + [Link] - 1];
[Link](data, 0, sentData, 0, [Link]);
[Link](remainder, 0, sentData, [Link], [Link] - 1);
[Link]("Simulated sent data:");

for (int i = 0; i < [Link]; i++) {


[Link](sentData[i]);
}
[Link]();
// Check the received data for errors
receive(sentData, divisor);
}
static int[] divide(int[] oldData, int[] divisor) {
int[] data = new int[[Link] + [Link] - 1];
[Link](oldData, 0, data, 0, [Link]);
for (int i = 0; i < [Link]; i++) {
if (data[i] == 1) {
for (int j = 0; j < [Link]; j++) {
data[i + j] ^= divisor[j]; // XOR operation
}
}
}
int[] remainder = new int[[Link]];
[Link](data, [Link] - [Link] + 1, remainder, 0, [Link] - 1);
return remainder;
}
static void receive(int[] data, int[] divisor) {
int[] remainder = divide(data, divisor);

// Check for errors


boolean hasError = false;
for (int bit : remainder) {
if (bit != 0) {
hasError = true;
break;
}
}
if (hasError) {
[Link]("There is an error in received data.");
} else {
[Link]("Data was received without any error.");
}
}
}
Output:

Enter the size of the data:


5
Enter the data bits (0 or 1):
Enter bit number 1: 1
Enter bit number 2: 0
Enter bit number 3: 0
Enter bit number 4: 1
Enter bit number 5: 1

Enter the size of the divisor:


4
Enter the divisor bits (0 or 1):
Enter bit number 1: 1
Enter bit number 2: 0
Enter bit number 3: 1
Enter bit number 4: 1

The CRC code generated is:


1001100

Simulated sent data:


1001100

Data was received without any error.


Write a Java program that implements Hamming Code for error detection and correction. The
Hamming code can detect and correct single-bit errors in transmitted data. Your task is to
simulate both the sender and receiver sides of Hamming Code by generating the Hamming code
at the sender side and detecting/correcting errors at the receiver side.

import [Link];

class Hamming {
public static void main(String args[]) {
Scanner scan = new Scanner([Link]);
[Link]("Enter the number of bits for the Hamming data:");
int n = [Link]();
int a[] = new int[n];
for (int i = 0; i < n; i++) {
[Link]("Enter bit no. " + (n - i) + ":");
a[n - i - 1] = [Link]();
}
[Link]("You entered:");
for (int i = 0; i < n; i++) {
[Link](a[n - i - 1]);
}
[Link]();
int b[] = generateCode(a);
[Link]("Generated code is:");
for (int i = 0; i < [Link]; i++) {
[Link](b[[Link] - i - 1]);
}
[Link]();
[Link]("Enter position of a bit to alter to check for error detection at the receiver end
(0 for no error):");
int error = [Link]();
if (error != 0) {
b[error - 1] = (b[error - 1] + 1) % 2;
}
[Link]("Sent code is:");
for (int i = 0; i < [Link]; i++) {
[Link](b[[Link] - i - 1]);
}
[Link]();
receive(b, [Link] - [Link]);
}
static int[] generateCode(int a[]) {
int b[];
int i = 0, parity_count = 0, j = 0, k = 0;

while (i < [Link]) {


if ([Link](2, parity_count) == i + parity_count + 1) {
parity_count++;
} else {
i++;
}
}
b = new int[[Link] + parity_count];
for (i = 1; i <= [Link]; i++) {
if ([Link](2, j) == i) {
b[i - 1] = 2;
j++;
} else {
b[k + j] = a[k++];
}
}
for (i = 0; i < parity_count; i++) {
b[((int) [Link](2, i)) - 1] = getParity(b, i);
}
return b;
}
static int getParity(int b[], int power) {
int parity = 0;
for (int i = 0; i < [Link]; i++) {
if (b[i] != 2) {
int k = i + 1;
String s = [Link](k);
int x = (([Link](s)) / ((int) [Link](10, power))) % 10;
if (x == 1) {
if (b[i] == 1) {
parity = (parity + 1) % 2;
}
}
}
}
return parity;
}
static void receive(int a[], int parity_count) {
int power;
int parity[] = new int[parity_count];
String syndrome = new String();

for (power = 0; power < parity_count; power++) {


for (int i = 0; i < [Link]; i++) {
int k = i + 1;
String s = [Link](k);
int bit = (([Link](s)) / ((int) [Link](10, power))) % 10;
if (bit == 1) {
if (a[i] == 1) {
parity[power] = (parity[power] + 1) % 2;
}
}
}
syndrome = parity[power] + syndrome;
}
int error_location = [Link](syndrome, 2);
if (error_location != 0) {
[Link]("Error is at location " + error_location + ".");
a[error_location - 1] = (a[error_location - 1] + 1) % 2;
[Link]("Corrected code is:");
for (int i = 0; i < [Link]; i++) {
[Link](a[[Link] - i - 1]);
}
[Link]();
} else {
[Link]("There is no error in the received data.");
}
[Link]("Original data sent was:");
power = parity_count - 1;
for (int i = [Link]; i > 0; i--) {
if ([Link](2, power) != i) {
[Link](a[i - 1]);
} else {
power--;
}
}
[Link]();
}
}
Output:

Enter the number of bits for the Hamming data:


4
Enter bit no. 4:
1
Enter bit no. 3:
0
Enter bit no. 2:
1
Enter bit no. 1:
1

You entered:
1101

Generated code is:


1110010

Enter position of a bit to alter to check for error detection at the receiver end (0 for no error):
4

Sent code is:


1111010

Error is at location 4.
Corrected code is:
1110010

There is no error in the received data.

Original data sent was:


1101

You might also like