Updated Computer Network

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

NOIDA INSTITUTE OF ENGINEERING

AND TECHNOLOGY GREATER


NOIDA-201306
(An Autonomous Institute)

COMPUTER SCIENCE & ENGINEERING

Session (2022 – 2023)

LAB FILE
ON
Computer Network Lab
(ACSE0652)
(6th Semester)

Submitted To: Submitted By:

Mr. Ashish Mathur Aryan Singh

2001330100072

Affiliated to Dr. A.P.J Abdul Kalam Technical University, Uttar Pradesh,


Lucknow.
INDEX

Sr. List of Experiment Date Signature


No

1 Introduction to Network Devices (Repeater, Hub, Bridge, Switch,


Router, Gateways, NIC etc.
2 To make UTP cable with RJ45 connector and built and test simple
network using UTP cable (crossover) and a hub based (straight
thru) cable.

3 Introduction to CISCO Packet Tracer. Design bus, star, mesh and


ring topology and check the connectivity using ping command

4 Test the Network connection using ping command and use of


ipconfig, and trcert command provided by TCP/IP.

5 Performing an Initial Switch Configuration

6 Implementation of CRC algorithm in any language like C++, Java


or Python.
7 Implementation of data link layer framing method such as bit
stuffing in any language like C++, Java or Python.

8 Implementation of hamming code (7, 4) code to limit the noise. We


have to code the bit data in to 7bit data by adding 3 parity bits.
Implement in in any language like C++, Java or Python.

9 Write a program in java to find the IP address of the system.

10 Write a program in java to find the IP address of the any site if


name is given.
EXPERIMENT- 1
AIM: - Introduction to Network Devices (Repeater, Hub, Bridge, Switch, Router,
Gateways, NIC etc.

1) 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. An important point
to be noted about repeaters is that 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.

Repeater Fig. 1.1


2) 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. In
other words, collision domain of all hosts connected through Hub
remains one. Also, they do not have intelligence to find out best path
for data packets which leads to inefficiencies and wastage.

Types of Hub

Active Hub:- These are the hubs which have their own power supply and can
clean, boost and relay the signal along with the network. It serves both as a
repeater as well as wiring center. These are used to extend the maximum
distance between nodes.

Fig 1.2
Passive Hub :- These are the hubs which collect wiring from nodes and
power supply from active hub. These hubs relay signals onto the network
without cleaning and boosting them and can’t be used to extend the distance
between nodes.

Fig. 1.3
3)Bridge – A bridge operates at 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 2port device.

Fig. 1.4
Types of Bridges
Transparent Bridges: - These are the bridge in which the stations are
completely unaware of the bridge’s existence i.e whether or not a bridge is
added or deleted from the network, reconfiguration of the stations is
unnecessary. These bridges make use of two processes i.e bridge forwarding
and bridge learning.
Source Routing Bridges: - In these bridges, routing operation is performed
by source station and the frame specifies which route to follow.The hot can
discover frame by sending a special frame called discovery frame, which spreads
through the entire network using all possible paths to destination.

4)Switch – A switch is a multiport bridge with a buffer and a design that can
boost its efficiency (a large number of ports imply less traffic) and
performance. A switch is a data link layer device. The switch can perform
error checking before forwarding data, that makes it very efficient as it does
not forward packets that have errors and forward good packets selectively to
correct port only. In other words, switch divides collision domain of hosts,
but broadcast domain remains same.

5)Routers – A router is a device like a switch that routes data packets based on
their IP addresses. Router is mainly a Network Layer device. Routers
normally connect LANs and WANs together and have a dynamically updating
routing table based on which they make decisions on routing the data packets.
Router divide broadcast domains of hosts connected through it. A router is
connected to two or more data lines from different IP networks. When a data
packet comes in on one of the lines, the router reads the network address
information in the packet header to determine the ultimate destination. Then,
using information in its routing table or routing policy, it directs the packet to
the next network on its journey.

The most familiar type of IP routers are home and small office routers that
simply forward IP packets between the home computers and the Internet.
More sophisticated routers, such as enterprise routers, connect large business
or ISP networks up to the powerful core routers that forward data at high
speed along the optical fiber lines of the Internet backbone.

Fig. 1.5

6)Gateway – A gateway, as the name suggests, is a passage to connect two


networks together that may work upon different networking models. They
basically work as the messenger agents that take data from one system,
interpret it, and transfer it to another system. Gateways are also called protocol
converters and can operate at any network layer. Gateways are generally more
complex than switch or router.
Fig. 1.6
7) NIC - A network interface card (NIC) is a hardware component without
which a computer cannot be connected over a network. It is a circuit board
installed in a computer that provides a dedicated network connection to the
computer. It is also called network interface.

Fig. 1.7
EXPERIMENT- 2
AIM- To make UTP cable with RJ45 connector and built and test simple
network using UTP cable (crossover) and a hub based (straight thru)
cable.

Theory- Physical layer defines the cable or physical medium itself, e.g., thinned, thicket, unshielded
twisted pairs (UTP). It transmits raw bit stream over physical cable, defines cables, cards, and
physical aspects, defines NIC attachments to, hardware, how cable is attached to NIC, defines
techniques to transfer bit stream to cable. All media are functionally equivalent. The main difference
is in convenience and cost of installation and maintenance. Network Cabling Cable is the medium
through which information usually moves from one network device to another. There are several
types of cable which are commonly used with LANs. In some cases, a network will utilize only one
type of cable, other networks will use a variety of cable types. The type of cable chosen for a network
is related to the network's topology, protocol, and size. Types of cables used in networks are:

1. Unshielded Twisted Pair (UTP) Cable


2. Shielded Twisted Pair (STP) Cable
3. Coaxial Cable
4. Fiber Optic Cable

Table

Ethernet Cable Summary

Specifications Cable Type Maximum length

10BaseT Unshielded Twisted Pair 100 meters

10 Base 2 Thin coaxial 185 meters

10 Base 5 Thin coaxial 500 meters

10BaseF Fibre Optic 2000 meters

100BaseT Unshielded Twisted Pair 100 meters

100BaseTX Unshielded Twisted Pair 220 meters


Unshielded Twisted Pair Connector-The standard connector for unshielded twisted pair cabling
is an RJ- 45 connector.

Figure 1- 1

Shielded Twisted Pair (STP) Cable -A disadvantage of UTP is that it may be susceptible to
radio and electrical frequency interference. Shielded twisted pair (STP) is suitable for
environments with electrical interference; however, the extra shielding can make the cables
quite bulky. Shielded twisted pair is often used on networks using Token Ring topology.

Ethernet Cable: color – code Standards


T-568A Straight-Through Ethernet Cable

Figure 1- 2

The T-568A standard is supposed to be used in new network installations. Most off-the-shelf
Ethernet cables are still of the T-568B standard; however, it makes no functional difference.

T-568B Straight-Through Ethernet Cable

Figure 1. 3

Both the T-568A and the T-568B standard Straight-Through cables are used most often as
patch cords for Ethernet connections. If we require a cable to connect two Ethernet devices
directly together without a hub or when connecting two hubs together, we need to use a
Crossover cable instead.
RJ-45 Crossover Ethernet Cable

Figure 1.4

Standard End Crossover End


Pin 1 White/Orange Pin 1 White/Green
Pin 2 Orange Pin 2 Green
Pin 3 White/Green Pin 3 White/Orange
Pin 4 Blue Pin 4
Pin 5 White/Blue Pin 5 White/Blue
Pin 6 Green Pin 6 Orange
Pin 7 White/Brown Pin 7 White/Brown
Pin 8 Brown Pin 8 Brown
Crossover Ethernet cable is to wire one end using the T-568A standard and the other end using
the T- 568B standard. Another way of remembering the color coding is to simply switch the
green set of wires in place with the orange set of wires. Specifically, switch the solid Green
(G) with the solid Orange, and switch the green/white with the orange/white.

Figure 1- 5

By looking at a T-568A UTP Ethernet straight-thru cable and an Ethernet crossover cable with
a T- 568B end, we see that the TX (transmitter) pins are connected to the corresponding RX
(receiver) pins, plus to plus and minus to minus. You can also see that both the blue and brown
wire pairs on pins 4, 5, 7, and 8 are not used in either standard. What you may not realize is
that, these same pins 4, 5, 7, and 8 are not used or required in 100BASE-TX as well. So why
bother using these wires, well for one thing its simply easier to make a connection with all the
wires grouped together. Otherwise you'll be spending time trying to fit those tiny little wires
into each of the corresponding holes in the RJ-45 connector.

Procedure-

1.Start on one end of cable and strip the cable jacket off using a stripper.
2.Spread, untwist the pairs, and arrange the wires in the order of the desired cable
end. Flatten the end between your thumb and forefinger. Trim the ends of the wires
so they are even with one another.
3.Hold the RJ-45 plug with the clip facing down.Push the wires firmly into the plug.
Inspect each wire is flat even at the front of the plug. Check the order of the
wires.Check that the jacket is fitted right against the stop of the plug.Carefully hold the
wire and firmly crimp the RJ-45 with the crimper.
4.Check the color orientation, check that the crimped connection is not about to come
apart, and check to see if the wires are flat against the front of the plug
5.Similarly make end 2 according to the color coding for straight through cable or
crossover cable on the basis of requirement.

Connecting PC’s using direct cable UTP –


1. use crossover UTP cable.
2. Insert RJ45 connector to both PC’s NIC card.
3. restart both computers and both of them detect the network after logon.

Figure 1- 6

Connecting PC to hub-

1 use straight through UTP cable.

2.Insert RJ45 connector to computer’s NIC card and other end to HUB.
Precautions-

• A straight-thru cable has identical ends.


• A crossover cable has different ends.
• A straight-thru is used as a patch cord in Ethernet connections.
• A crossover is used to connect two Ethernet devices without a hub or for connecting
two hubs.
• No more than 1/2" of the Ethernet cable should be untwisted otherwise it will be
susceptible to crosstalk.

EXPERIMENT-3
AIM: - Introduction to CISCO Packet Tracer. Design bus , star ,
mesh and ring toplogy and check the connectivity using ping
command
A) CISCO PACKET TRACER

Packet Tracer is a cross-platform visual simulation tool designed by Cisco


Systems that allows users to create network topologies and imitate modern
computer networks. The software allows users to simulate the configuration
of Cisco routers and switches using a simulated command line interface.
Packet Tracer makes use of a drag and drop user interface, allowing users to
add and remove simulated network devices as they see fit. The software is
mainly focused towards Certified Cisco Network Associate Academy
students as an educational tool for helping them learn fundamental CCNA
concepts.
Packet Tracer can be run on Linux and Microsoft Windows. Similar Android and iOS apps are
also available. Packet Tracer allows users to create simulated network topologies by

dragging and dropping routers, switches and various other types of network
devices. A physical connection between devices is represented by a "cable"
item. Packet Tracer supports an array of simulated Application Layer
protocols, as well as basic routing with RIP, OSPF, EIGRP, BGP, to the
extents required by the current CCNA curriculum. As of version 5.3, Packet
Tracer also supports the Border Gateway Protocol.
In addition to simulating certain aspects of computer networks, Packet
Tracer can also be used for collaboration. As of Packet Tracer 5.0, Packet
Tracer supports a multi-user system that enables multiple users to connect
multiple topologies together over a computer network. Packet Tracer also
allows instructors to create activities that students have to complete. Packet
Tracer is often used in educational settings as a learning aid. Cisco Systems
claims that Packet Tracer is useful for network experimentation.
Packet Tracer allows students to design complex and large networks, which is
often not feasible with physical hardware, due to costs. Packet Tracer is
commonly used by CCNA Academy students, since it is available to them for
free. However, due to functional limitations, it is intended by CISCO to be
used only as a learning aid, not a replacement for Cisco routers and switches.
The application itself only has a small number of features found within the
actual hardware running a current Cisco IOS version. Thus, Packet Tracer is
unsuitable for modelling production networks. It has a limited command set,
meaning it is not possible to practice all of the IOS commands that might be
required. Packet Tracer can be useful for understanding abstract networking
concepts, such as the Enhanced Interior Gateway Routing Protocol by
animating these elements in a visual form. Packet Tracer is also useful in
education by providing additional components, including an authoring
system, network protocol simulation and improving knowledge an
assessment system.
1. b) Bus Topology -A bus topology is a topology for a Local Area
Network (LAN) in which all the nodes are connected to a single cable.
The cable to which the nodes connect is called a "backbone". If the
backbone is broken, the entire segment fails.
2. Mesh Topology- Mesh topology is a type of networking where all
nodes cooperate to distribute data amongst each other. This topology
setup allows for most transmissions to be distributed even if one of the
connections goes down. It is a topology commonly used for wireless
networks.
3. Ring Topology- A ring network is a network topology in which
each node connects to exactly two other nodes, forming a single
continuous pathway for signals through each node
- a ring. Data travels from node to node, with each node along the way handling every
packet.

Star Topology-A star topology is a topology for a Local Area Network


(LAN) in which all nodes are individually connected to a central
connection point, like a hub or a switch. A star takes more cable than e.g. a
bus, but the benefit is that if a cable fails, only one node will be brought
down.
Experiment - 4
AIM: Test the Network connection using ping command and use of
ipconfig, and tracert command provided by TCP/IP.
Theory and Procedure

1.ipconfig

This command details how IP is setup on the machine you are logged into.

At the command prompt, type: ipconfig


There are also a variety of switches for ipconfig that add functions. These are
invoked by entering "ipconfig/{switch}". To obtain a list of switches, enter
"ipconfig /?" or "ipconfig -?". These are shown in the figure below.

/? Display this help message.

/all Display full configuration information.


/release Release the IP address for the specified adapter.

/renew Renew the IP address for the specified adapter.

2. TRACERT
This command shows you all the routers that your TCP/IP message
goes through in order to make a connection to another IP address.

At the command prompt, type: tracert xxx Where xxx is the IP address or URL
of the machine that we are trying to connect to.
e.g. tracert192.168.0.18

e.g. tracert yahoo.com

3. Ping command

The ping command is a Command Prompt command used to test the ability of the source
computer to reach a specified destination computer. The ping command is usually used
as a simple way to verify that a computer can communicate over the network with
another computer or network device.

The ping command operates by sending Internet Control Message Protocol (ICMP) Echo
Request messages to the destination computer and waiting for a response. How many
of those responses are returned, and how long it takes for them to return, are the two
major pieces of information that the ping command provides.

For example, you might find that there are no responses when pinging a network
printer, only to find out that the printer is offline and its cable needs replaced. Or maybe
you need to ping a router to verify that your computer can connect to it, to eliminate it
as a possible cause for a networking issue.

Example:
Ping www.google.com

Experiment-5
AIM :- Performing an Initial Switch Configuration
Topology Diagram

Objectives
 Perform an initial configuration of a Cisco Catalyst 2960 switch.

Background / Preparation
In this activity, you will configure these settings on the customer Cisco Catalyst 2960 switch:
 Host name
 Console password
 vty password
 Privileged EXEC mode password
 Privileged EXEC mode secret
 IP address on VLAN1 interface
 Default gateway
Note: Not all commands are graded by Packet Tracer.

Step 1: Configure the switch host name.


a. From the Customer PC, use a console cable and terminal emulation software to
connect to the console of the customer Cisco Catalyst 2960 switch.
b. Set the host name on the switch to CustomerSwitch using these commands.

Switch>enable

Switch#configure terminal

Switch(config)#hostname CustomerSwitch

Step 2: Configure the privileged mode password and secret.


a. From global configuration mode, configure the password as cisco.

CustomerSwitch(config)#enable password cisco


b. From global configuration mode, configure the secret as cisco123.

CustomerSwitch(config)#enable secret cisco123

Step 3: Configure the console password.


a. From global configuration mode, switch to configuration mode to configure the console line.
CustomerSwitch(config)#line console 0

b. From line configuration mode, set the password to cisco and require the
password to be entered at login.

CustomerSwitch(config-line)#password cisco
CustomerSwitch(config-line)#login
CustomerSwitch(config-line)#exit

Step 4: Configure the vty password.


a. From global configuration mode, switch to the configuration mode for the vty lines 0 through
15.

CustomerSwitch(config)#line vty 0 15

b. From line configuration mode, set the password to cisco and require the
password to be entered at login.

CustomerSwitch(config-line)#password cisco
CustomerSwitch(config-line)#login
CustomerSwitch(config-line)#exit

Step 5: Configure an IP address on interface VLAN1.


From global configuration mode, switch to interface configuration mode for VLAN1,
and assign the IP address 192.168.1.5 with the subnet mask of 255.255.255.0.
CustomerSwitch(config)#interface vlan 1

CustomerSwitch(config-if)#ip address 192.168.1.5 255.255.255.0

CustomerSwitch(config-if)#no shutdown
CustomerSwitch(config-if)#exit

Step 6: Configure the default gateway.


a. From global configuration mode, assign the default gateway to 192.168.1.1.

CustomerSwitch(config)#ip default-gateway 192.168.1.1

b. Click the Check Results button at the bottom of this instruction window to check your work
Step 7: Verify the configuration.
The Customer Switch should now be able to ping the ISP Server at 209.165.201.10.
The first one or two pings may fail while ARP converges.

CustomerSwitch(confi
g)#end
CustomerSwitch#ping
209.165.201.10

Type escape sequence to abort.


Sending 5, 100-byte ICMP Echos to 209.165.201.10, timeout is 2 seconds:
..!!!
Success rate is 60 percent (3/5), round-trip min/avg/max =

181/189/197 ms CustomerSwitch#

Reflection
a. What is the significance of assigning the IP address to the VLAN1 interface instead of
any of the Fast Ethernet interfaces?

b. What command is necessary to enforce password authentication on the console and vty lines?

c. How many gigabit ports are available on the Cisco Catalyst 2960 switch that you used in the
activity?

Experiment – 6
AIM :- Implementation of CRC algorithm in any language like C++ , Java or
Python.
Java
// Java code to implement the approach

Import java.util.Arrays;

Class Program {

// Returns XOR of 'a' and 'b'

// (both of same length)

static String Xor(String a, String b)

// Initialize result

String result = "";

int n = b.length();

// Traverse all bits, if bits are

// same, then XOR is 0, else 1

for (int I = 1; i < n; i++) {

if (a.charAt(i) == b.charAt(i))

result += “0”;

else
result += "1";
}

return result;

// Performs Modulo-2 division

static String Mod2Div(String dividend, String divisor)

{
// Number of bits to be XORed at a time. int

pick = divisor.length();

// Slicing the dividend to appropriate

// length for particular step

String tmp = dividend.substring(0, pick);


int n = dividend.length();
while (pick < n) {

if (tmp.charAt(0) == '1')
// Replace the dividend by the result

// of XOR and pull 1 bit down

tmp = Xor(divisor, tmp)

+ dividend.charAt(pick);

else
// If leftmost bit is '0'.

// If the leftmost bit of the dividend (or

// the part used in each step) is 0, the

// step cannot use the regular divisor; we


// need to use an all-0s divisor.

tmp = Xor(new String(new char[pick])

.replace("\0", "0"),

tmp)

+ dividend.charAt(pick);
// Increment pick to move further

pick += 1;

// For the last n bits, we have to carry it out

// normally as increased value of pick will cause

// Index Out of Bounds.


if (tmp.charAt(0) == '1')

tmp = Xor(divisor, tmp);

else

tmp = Xor(new String(new char[pick])

.replace("\0", "0"),

tmp);
return tmp;
}
// Function used at the sender side to encode

// data by appending remainder of modular division

// at the end of data.

static void EncodeData(String data, String key)

int l_key = key.length();


// Appends n-1 zeroes at end of data
String appended_data= (data+ new
String(new char[l_key - 1])

.replace("\0", "0"));
String remainder = Mod2Div(appended_data, key);

// Append remainder in the original data

String codeword = data + remainder;

System.out.println("Remainder : " + remainder);

System.out.println("Encoded Data (Data +

Remainder) :" + codeword+ "\n");

// checking if the message received by receiver is

// correct or not. If the remainder is all 0 then it is

// correct, else wrong.

static void Receiver(String data, String key)


{

String currxor= Mod2Div(data.substring(0, key.length()), key); int curr = key.length();


while (curr != data.length()) {

if (currxor.length() != key.length()) {

currxor += data.charAt(curr++);

else {

currxor = Mod2Div(currxor, key);

}
if (currxor.length() == key.length()) {

currxor = Mod2Div(currxor, key);

if (currxor.contains("1"))

System.out.println("there is some error in data");

else {

System.out.println("correct message received");

// Driver code

public static void main(String[] args)

String data = "100100";

String key = "1101";


System.out.println("\nSender side...");

EncodeData(data, key);

System.out.println("Receiver side...");

Receiver(data+Mod2Div(data+new String(new char[key.length() - 1])

.replace("\0", "0"),key),key);

OUTPUT

Experiment - 7
AIM :- Implementation of data link layer framing method such as bit stuffing
in any language like C++ ,Java or Python.

// Java program for the above approach


class GFG {
// Function for bit stuffing

static void bitStuffing(int N, int arr[])

{
// Stores the stuffed array

int[] brr = new int[30];

// Variables to traverse arrays

int i, j, k;

i = 0;

j = 0;

// Loop to traverse in the range [0, N)

while (i < N) {

// If the current bit is a set bit if (arr[i] ==

1) {

// Stores the count of consecutive ones int count = 1;

// Insert into array brr[]


brr[j] = arr[i];
// Loop to check for

// next 5 bits

for (k = i + 1; k < N && arr[k] == 1


&& count < 5;

k++) {

j++;

brr[j] = arr[k]; count++;


// If 5 consecutive set bits

// are found insert a 0 bit if (count == 5) {

j++;

brr[j] = 0;

i = k;

}
// Otherwise insert arr[i] into

// the array brr[] else {

brr[j] = arr[i];

} i++; j++;

}
// Print Answer for (i

= 0; i < j; i++)

System.out.printf("%d", brr[i]);
}
// Driver Code

public static void main(String[] args)

int N = 6;

int arr[] = { 1, 1, 1, 1, 1, 1 };
bitStuffing(N, arr);

}
OUTPUT

Experiment - 8
AIM :- Implementation of hamming code (7, 4) code to limit the noise. We
have to code the bit data in to 7bit data by adding 3 parity bits. Implement in
in any language like C++ , Java or Python.

// Python program to demonstrate


# hamming code
def calcRedundantBits(m):
# Use the formula 2 ^ r >= m + r + 1

# to calculate the no of redundant bits.

# Iterate over 0 .. m and return the value

# that satisfies the equation

for i in range(m):

if(2**i >= m + i + 1):

return i

def posRedundantBits(data, r):

# Redundancy bits are placed at the positions

# which correspond to the power of 2.


j=0

k=1

m = len(data)

res = ''
# If position is power of 2 then insert '0'

# Else append the data

for i in range(1, m + r+1):

if(i == 2**j):

res = res + '0'

j += 1

else:

res = res + data[-1 * k] k += 1


# The result is reversed since positions

are

# counted backwards. (m + r+1 ... 1)

return res[::-1]

def calcParityBits(arr, r):

n = len(arr)

# For finding rth parity bit, iterate over

# 0 to r - 1
for i in range(r):

val = 0

for j in range(1, n + 1):


# If position has 1 in ith significant
# position then Bitwise OR the array value
# to find parity bit value.
if(j & (2**i) == (2**i)):

val = val ^ int(arr[-1 * j])

# -1 * j is given since array is reversed


# String Concatenation

# (0 to n - 2^r) + parity bit + (n - 2^r + 1 to n)


arr = arr[:n-(2**i)] + str(val) + arr[n-(2**i)+1:]

return arr

def detectError(arr, nr):

n = len(arr)

res = 0

# Calculate parity bits again

for i in range(nr):

val = 0

for j in range(1, n + 1):

if(j & (2**i) == (2**i)):


val = val ^ int(arr[-1 * j])
# Create a binary no by appending

# parity bits together.

res = res + val*(10**i)

# Convert binary to decimal

return int(str(res), 2)

#’ Enter the data to be

transmitted ‘

data = '1011001'

# ‘Calculate the no of Redundant

Bits Required ‘

m = len(data)

r = calcRedundantBits(m)
# Determine the positions of Redundant Bits
arr = posRedundantBits(data, r)

# Determine the parity bits

arr = calcParityBits(arr, r)

# Data to be transferred

print("Data transferred is " +

arr)

# Stimulate error in transmission

by changing

# a bit value.

# 10101001110 -> 11101001110, error in 10th position.


arr = '11101001110'
print("Error Data is " + arr)
correction = detectError(arr, r)

if(correction==0):
print("There is no error in the received message.")

else:

print("The position of error is ",len(arr)-correction+1,"from the left")

OUTPUT

Experiment - 9
AIM : - Write a program in java to find the IP address of the system.

// Java program to find IP address of your


computer
// java.net.InetAddress class provides method to get

// IP of any host name

import java.net.*;

import java.io.*;

import java.util.*;
import java.net.InetAddress;
public class JavaProgram

public static void main(String args[]) throws Exception

// Returns the instance of InetAddress containing

// local host name and address

InetAddress localhost = InetAddress.getLocalHost();

System.out.println("System IP Address : " +

(localhost.getHostAddress()).trim());
// Find public IP address String

systemipaddress = "";

try

URL url_name = new URL("http://bot.whatismyipaddress.com");


BufferedReader sc = new BufferedReader(new InputStreamReader(url_name.openStream()));
// reads system IPAddress

systemipaddress = sc.readLine().trim();
}

catch (Exception e)

systemipaddress = "Cannot Execute Properly";

System.out.println("Public IP Address: " + systemipaddress +"\n");

Output:
System IP Address : 10.0.8.204
Public IP Address : 35.168.48.97

Experiment-10
AIM :- Write a program in java to find the IP address of the any site if name is
given.

// Java program to demonstrate


// how to fetch public IP Address

import java.net.*;

import java.*;

class GFG {

public static void main(String args[])

throws UnknownHostException

String s = "https:// www.google.com/";


try {

InetAddress ip = InetAddress.getByName(new URL(s).getHost());

System.out.println("Public IP Address of: " + ip);

catch (MalformedURLException e) {

// It means the URL is invalid System.out.println("Invalid URL");

Output:
Public IP Address of:
www.google.com/216.58.196.164

You might also like