0% found this document useful (0 votes)
44 views40 pages

Amit Kumar CN File

The document describes how to make an UTP cable with an RJ45 connector and build a simple network using UTP cable and a hub. It discusses the different types of cables used in networks like UTP, STP, coaxial and fiber optic cables. It also explains the T-568A and T-568B wiring standards for straight-through and crossover Ethernet cables.

Uploaded by

aryan rana
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)
44 views40 pages

Amit Kumar CN File

The document describes how to make an UTP cable with an RJ45 connector and build a simple network using UTP cable and a hub. It discusses the different types of cables used in networks like UTP, STP, coaxial and fiber optic cables. It also explains the T-568A and T-568B wiring standards for straight-through and crossover Ethernet cables.

Uploaded by

aryan rana
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
You are on page 1/ 40

NOIDA INSTITUTE OF ENGINEERING AND TECHNOLOGY

GREATER NOIDA-201306
(An Autonomous Institute)
School of Computer Sciences & Engineering in Emerging Technologies

Department of CSE (Artificial Intelligence)

Session (2023 – 2024)

LAB FILE

ON

Computer Network Lab

(ACSE-0552)
(5th Semester)

Submitted To: Submitted By:

Dr. Prasanna Singh Name: Amit Kumar


Ms. Purnima Pal Roll No: 2101331520016

Affiliated to Dr. A.P.J Abdul Kalam Technical University, Uttar Pradesh, Lucknow
NOIDA INSTITUTE OF ENGINEERING AND TECHNOLOGY
GREATER NOIDA-201306
(An Autonomous Institute)
School of Computer Sciences & Engineering in Emerging Technologies

Computer Network Lab (ACSE-0552)

INDEX
PAGE Grade
S.NO PRACTICAL CONDUCTED DATE SIGN
NO

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 1

AIM- To make an UTP cable with RJ45 connector and built and test simple network using
UTP cable (crossover) and a hub based cable.

Theory-
Physical layer defines the cable or physical medium itself, e.g., thinnet, thicknet, 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

5. wireless media

CN LAB 2101331520016 AMIT KUMAR


Categories of Unshielded Twisted Pair defined Ethernet Cable Summary
by EIA/TIA
Type Use Specificatio Maximum
Cable Type
Category 1 Voice Only (Telephone Wire) ns length

Category 2 Data to 4 Mbps (LocalTalk) Unshielded


10BaseT Twisted 100 meters
Category 3 Data to 10 Mbps (Ethernet)
Pair
Data to 20 Mbps (16 Mbps Token
Category 4 10Base2 Thin Coaxial 185 meters
Ring)
10Base5 Thick Coaxial 500 meters
Category 5 Data to 100 Mbps (Fast Ethernet)
10BaseF Fiber Optic 2000 meters
Category 6 10 Gbps (Gigabit Ethernet) 55 meters
Unshielded
Category 7 10 Gbps (Gigabit Ethernet) 100 meters Twisted
100BaseT 100 meters
Pair

Unshielded
100BaseTX Twisted 220 meters
Pair

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

Fig. 2. RJ-45 connector


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

CN LAB 2101331520016 AMIT KUMAR


T-568A Straight-Through Ethernet Cable

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

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

CN LAB 2101331520016 AMIT KUMAR


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 Blue

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.

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.

Deciding which cable to use :


here's a small chart that will give an idea which cable should go where:

CN LAB 2101331520016 AMIT KUMAR


computer to computer crossover cable

straight through
computer to hub
cable

hub port to hub port crossover cable

straight through
hub uplink to hub port
cable

computer to broadband router straight through


port cable

straight through
computer to switch
cable

computer to cable modem crossover cable

cable modem to router crossover cable

straight through
hub uplink to switch port
cable

Two computers scenario:


If we have only two computers, it will need two nic's and a crossover cable. If you also
require both computers to have internet access, then you could either
(a). Install another NIC (connect it to the cable/DSL modem with a crossover cable) or fax
modem in one and connect it to the internet, then use a software proxy, ICS, Wingate, etc to
share the internet.

OR
(b). Get a router (Connect it using a crossover cable to the cable modem and
connect the computers to the built in switch on the router. Some routers don't have built in
switches, in this case you will need to get a switch or hub.

CN LAB 2101331520016 AMIT KUMAR


c) More than two computers scenario (hub/switch cascading):
With more computers we will need a hub/switch and straight through cables, connect all
computers to the hub/switch with straight through cable. If you run out of ports then add
another hub/switch to your network. Connect the uplink of one hub/switch to a port on the
other hub/switch using a straight through cable, or connect port to port using a
crossover cable.

If we have more than two hubs/switches, then connect all the hub/switches using uplink
ports and straight through cables, to regular ports on a main hub/switch.

If you require internet connectivity:


(a) Install another NIC (connect it to the cable/DSL modem with a crossover cable), or fax
modem in one machine and connect it to the internet. Use a software proxy, ICS, Wingate,
etc to share the internet.
Now connect the gateway computer and the rest of the computers to the hub's ports using
straight through cables.

OR
(b) Using a broadband router, connect a cable modem with a crossover cable to the WAN
port of the router, then connect the other computers to the router's LAN ports If you do not
have enough ports then get more hub/switches. Connect the uplink ports to the router's LAN
port with straight through cables and connect your computers to the hubs/switches.

CN LAB 2101331520016 AMIT KUMAR


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.

Connecting PC to hub-

1 use straight through UTP cable.

CN LAB 2101331520016 AMIT KUMAR


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

3.Switch o power of HUB and computer.

Result-

The study of an UTP cable with RJ-45 connector is completed, and build the simple
network using UTP cable and a hub based network successfully.

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.
● Do not deform, do not bend, do not stretch, do not staple, do not run parallel with
power cables, and do not run Ethernet cables near noise inducing components.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 2
AIM: - Introduction to Network Devices (Repeater, Hub, Bridge, Switch,
Router, Gateways, NIC etc.

Theory:-

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.
2.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

CN LAB 2101331520016 AMIT KUMAR


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 2.2

Fig. 2.3

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.

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 2 port device.

CN LAB 2101331520016 AMIT KUMAR


Fig. 2.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

CN LAB 2101331520016 AMIT KUMAR


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. 2.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.

CN LAB 2101331520016 AMIT KUMAR


Fig. 2.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. 2.7

Results-

The study of important network devices is accomplished successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 3

AIM- Test the Network connection using ping command and use of
ipconfig, netstat and tracert command provided by TCP/IP.

Theory and Procedure-

(1) 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.

Ping Command Options

Item Explanation

-t Using this option will ping the target until you force it to stop by using Ctrl-C.

-a This ping command option will resolve, if possible, the hostname of an IP


address target.

- This option sets the number of ICMP Echo Requests to send, from 1 to 4294967295.
ncount The ping command will send 4 by default if -n isn't used.

-l size Use this option to set the size, in bytes, of the echo request packet from 32 to 65,527.
The ping command will send a 32-byte echo request if you don't use the -l option.

-f Use this ping command option to prevent ICMP Echo Requests from being
fragmented by routers between you and the target. The -f option is most often used
to troubleshoot Path Maximum Transmission Unit (PMTU) issues.

-i TTL This option sets the Time to Live (TTL) value, the maximum of which is 255.

CN LAB 2101331520016 AMIT KUMAR


Ping Command Options

-v TOS This option allows you to set a Type of Service (TOS) value. Beginning in Windows
7, this option no longer functions but still exists for compatibility reasons.

-rcount Use this ping command option to specify the number of hops between your
computer and the target computer or device that you'd like to be recorded and
displayed. The maximum value for count is 9, so use the tracert command instead if
you're interested in viewing all the hops between two devices.

-scount Use this option to report the time, in Internet Timestamp format, that each echo
request is received and echo reply is sent. The maximum value for count is 4,
meaning that only the first four hops can be time stamped.

- Specifying a timeout value when executing the ping command adjusts the amount of
wtimeo time, in milliseconds, that ping waits for each reply. If you don't use the -w option,
ut the default timeout value of 4000 is used, which is 4 seconds.

-R This option tells the ping command to trace the round trip path.

- Use this option to specify the source address.


Ssrcad
dr

-p Use this switch to ping a Hyper-V Network Virtualization provider address.

-4 This forces the ping command to use IPv4 only but is only necessary if target is a
hostname and not an IP address.

-6 This forces the ping command to use IPv6 only but as with the -4option, is only
necessary when pinging a hostname.

Target This is the destination you wish to ping, either an IP address or a hostname.

/? Use the help switch with the ping command to show detailed help about the
command's several options.

>> ping 127.0.01

In the above example, we're pinging 127.0.0.1, also called the IPv4 localhost IP address or
IPv4 loopback IP address, without options.

Using the ping command to ping 127.0.0.1 is an excellent way to test that Windows' network
features are working properly but it says nothing about your own network hardware or your
connection to any other computer or device. The IPv6 version of this test would be ping ::1.

CN LAB 2101331520016 AMIT KUMAR


(2.) ipconfig command

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.

ipconfig [/? | /all | /release [adapter] | /renew [adapter]]

/? 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.

For a detailed output of network parameters, use the command "ipconfig /all". Unless you are experienced
with networks, however, this may be more than we want to know.

(3) tracert command


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.

Here is the result of tracert from college computer to yahoo.com ( DNS has resolved the name “yahoo.com”
to 129.64.99.33)

Other options available in tracert command

tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

-d Do not resolve addresses to hostnames.

-h maximum_hops Maximum number of hops to search for target.

-j host-list Loose source route along host-list.

-w timeout Wait timeout milliseconds for each reply

CN LAB 2101331520016 AMIT KUMAR


(4) netstat command

The netstat command is used to display the TCP/IP network protocol statistics and information

NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]

-a Displays all connections and listening ports. (Server-side connections are normally not shown).

-e Displays Ethernet statistics. This may be combined with the -s option.

-n Displays addresses and port numbers in numerical form.

Shows connections for the protocol specified by proto; proto may be tcp or udp. If used with
-p proto
the -s option to display per-protocol statistics, proto may be tcp, udp, or ip.

-r Displays the contents of the routing table.

Displays per-protocol statistics. By default, statistics are shown for TCP, UDP and IP; the -p
-s
option may be used to specify a subset of the default.

Redisplays selected statistics, pausing interval seconds between each display. Press CTRL+C

interval to stop redisplaying statistics. If omitted, netstat will print the current configuration

information once.

(5) nslookup command

Stands for “Name Server Lookup” is a useful command for getting information from DNS
server. It is a network administration tool for querying the Domain Name System (DNS) to
obtain domain name or IP address mapping or any other specific DNS record. It is also used
to troubleshoot DNS related problems.

nslookup google.com :
nslookup followed by the domain name will display the “A Record” (IP Address) of the
domain. Use this command to find the address record for a domain. It queries to domain
name servers and get the details.

nslookup 192.168.0.10 :

Reverse DNS lookup you can also do the reverse DNS look-up by providing the IP
Address as argument to nslookup.

nslookup -type=any google.com

CN LAB 2101331520016 AMIT KUMAR


Lookup for any record we can also view all the available DNS records using -
type=any option.

nslookup -type=soa redhat.com :

Lookup for an soa record SOA record (start of authority), provides the authoritative
information about the domain, the e-mail address of the omain admin, the domain serial
number, etc

nslookup -type=ns google.com

Lookup for an ns record NS (Name Server) record maps a domain name to a list of
DNS servers authoritative for that domain. It will output the name serves which are
associated with the given domain.

nslookup -type=a google.com

Lookup for an a record We can also view all the available DNS records for a particular
record using -type=a option.

nslookup -type=mx google.com :

Lookup for an mx record MX (Mail Exchange) record maps a domain name to a list of
mail exchange servers for that domain. The MX record tells that all the mails sent to
“google.com” should be routed to the Mail server in that domain.

nslookup -type=txt google.com :

Lookup for an txt record TXT records are useful for multiple types of records like
DKIM, SPF, etc. You can find all TXT records configured for any domain using below
command.

Outputs: -

(Paste the screenshots)

(1) ping command

Example:

>> ping www.google.com

>> ping www.niet.co.in

>> ping 192.168.4.1

CN LAB 2101331520016 AMIT KUMAR


(2) ipconfig command

>> ipconfig

>> ipconfig/all

(3)tracert command
Example:

>> tracert 192.168.0.18

>>tracert yahoo.com

(4)netstat command

>> netstat-n

>> netstat-a

>> netstat-?

(5)nslookup command

Example:

>> nslookup google.com

>> nslookup niet.co.in

Result:-

All the required network commands are studied and successfully test the network connection
using ping command and use of ipconfig, netstat and tracert command provided by TCP/IP.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 4

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

Theory –
The data link layer is responsible for something called Framing, which is the division of
stream of bits from network layer into manageable units (called frames). Frames could be
of fixed size or variable size. In variable-size framing, we need a way to define the end of
the frame and the beginning of the next frame.
Bit stuffing is the insertion of non information bits into data. Note that stuffed bits should
not be confused with overhead bits.
Overhead bits are non-data bits that are necessary for transmission (usually as part of
headers, checksums etc.).

Example—
Bit sequence: 110101111101011111101011111110 (without bit stuffing)
Bit sequence: 110101111100101111101010111110110 (with bit stuffing)
After 5 consecutive 1-bits, a 0-bit is stuffed. Stuffed bits are marked bold.

Code- (with User defined input)

CN LAB 2101331520016 AMIT KUMAR


Input and Output-

Result-

The Implementation of data link layer framing method such as bit stuffing is done
successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 5

Aim - Implementation of CRC algorithm in any language like C++ , Java or Python.

Theory –
CRC (Cyclic Redundancy Check) is an error-checking technique used in network
communications to detect errors in transmitted data. It works by appending a fixed number of
bits to the data, called the "CRC checksum" or "CRC code," which is computed based on the
content of the data. At the receiver end, a CRC computation is performed on the received
data, including the CRC checksum. If the computed CRC code at the receiver matches the
received CRC code, it indicates that the data is likely free of errors. If the CRC codes don't
match, an error is detected.

Here's a Python implementation of CRC at the transmitter end and error detection at the
receiver end:
def generate_crc(data, divisor):
data = list(data)
divisor = list(divisor)
n = len(divisor) - 1
data += ['0'] * n # Append n zeros to the data

while '1' in data[:len(data) - n]: # Continue until there are no more 1s


left to shift
# Find the leftmost '1' in data
i = data.index('1')

# Perform bitwise XOR with the divisor


for j in range(n + 1):
data[i + j] = str(int(data[i + j]) ^ int(divisor[j]))

# The remainder is the CRC code


crc_code = ''.join(data[-n:])
return crc_code

def detect_error(data, divisor):


crc_code = data[-len(divisor):]
remainder = generate_crc(data, divisor)
return int(remainder, 2) != 0

if __name__ == "__main__":
data = "1101101101" # Data to be transmitted
divisor = "1011" # CRC divisor

# Generate CRC code at the transmitter end


crc_code = generate_crc(data, divisor)
transmitted_data = data + crc_code

CN LAB 2101331520016 AMIT KUMAR


# Simulate transmission (add noise)
received_data = transmitted_data
error_position = 5 # Simulate an error by flipping a bit
received_data = list(received_data)
received_data[error_position] = '0' if received_data[error_position] ==
'1' else '1'
received_data = ''.join(received_data)

# Detect the error at the receiver end


error_detected = detect_error(received_data, divisor)

if error_detected:
print("Error detected in the received data.")
else:
print("No error detected in the received data.")

Code-
class CRC:

def __init__(self):
self.cdw = ''

def xor(self,a,b):
result = []
for i in range(1,len(b)):
if a[i] == b[i]:
result.append('0')
else:
result.append('1')

return ''.join(result)

def crc(self,message, key):


pick = len(key)

tmp = message[:pick]

while pick < len(message):


if tmp[0] == '1':
tmp = self.xor(key,tmp)+message[pick]
else:
tmp = self.xor('0'*pick,tmp) + message[pick]

pick+=1

CN LAB 2101331520016 AMIT KUMAR


if tmp[0] == "1":
tmp = self.xor(key,tmp)
else:
tmp = self.xor('0'*pick,tmp)

checkword = tmp
return checkword

def encodedData(self,data,key):
l_key = len(key)
append_data = data + '0'*(l_key-1)
remainder = self.crc(append_data,key)
codeword = data+remainder
self.cdw += codeword
print("Remainder: " ,remainder)
print("Data: " ,codeword)

def reciverSide(self,key,data):
r = self.crc(data,key)
size = len(key)
print(r)
if r == size*0:
print("No Error")
else:
print("Error")

data = '100100'

key = '1101'

c = CRC()
c.encodedData(data,key)
print('---------------')
c.reciverSide(c.cdw,key)
print('---------------')
print(c.cdw)

Input and Output-

Result-

The Implementation of CRC algorithm is done successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 6

Aim -Implementation of Hamming code (7, 4) code to limit the noise in any language like
C++ , Java or Python.

Theory –

The Hamming Code method is a network technique designed by R.W.Hamming, for damage
and error detection during data transmission between multiple network channels. The
Hamming Code method is one of the most effective ways to detect single-data bit errors in
the original data at the receiver end. It is not only used for error detection but is also for
correcting errors in the data bit. The number of redundant bits can be calculated using the
following formula:

2^r ≥ m + r + 1

where, r = redundant bit, m = data bit

Part-1: Calculation of Hamming Code (7, 4) at the Transmitter End

def calculate_hamming_code(data):
# Calculate the number of parity bits needed
r = 0
while 2**r < len(data) + r + 1:
r += 1

# Initialize the Hamming code with zeros


hamming_code = [0] * (len(data) + r)

# Copy the data bits into the Hamming code, skipping the positions of
parity bits
data_bit_index = 0
for i in range(len(hamming_code)):
if (i + 1) & (i + 1 - 1) != 0:
hamming_code[i] = int(data[data_bit_index])
data_bit_index += 1

# Calculate the parity bits


for i in range(r):
position = 2**i - 1
for j in range(1, len(hamming_code) + 1):
if (j >> i) & 1 == 1:
hamming_code[position] ^= hamming_code[j - 1]

return hamming_code

data = "1010" # 4-bit data

CN LAB 2101331520016 AMIT KUMAR


hamming_code = calculate_hamming_code(data)
print(f"Transmitter End - Original Data: {data}")
print(f"Transmitter End - Hamming Code: {''.join(map(str, hamming_code))}")

Part-2: Detection and Correction of Hamming Code (7, 4) at the Receiver End
def detect_and_correct_hamming_code(received_code):
r = 0
while 2**r < len(received_code):
r += 1

error_position = 0
for i in range(r):
position = 2**i - 1
parity = 0
for j in range(1, len(received_code) + 1):
if (j >> i) & 1 == 1:
parity ^= received_code[j - 1]
if parity != 0:
error_position += position

if error_position > 0:
received_code[error_position - 1] ^= 1 # Correct the error

data_bits = [received_code[i] for i in range(len(received_code)) if (i +


1) & (i + 1 - 1) != 0]

return ''.join(map(str, data_bits))

received_code = hamming_code # Simulating reception of the Hamming code


corrected_data = detect_and_correct_hamming_code(received_code)

print(f"Receiver End - Received Hamming Code: {''.join(map(str,


received_code))}")
print(f"Receiver End - Corrected Data: {corrected_data}")

Code- (with User defined input)

def hamming_encode(data):
# Ensure the input data is 4 bits long
if len(data) != 4:
raise ValueError("Input data must be 4 bits long")

# Initialize the Hamming code with zeros


hamming_code = [0] * 7

CN LAB 2101331520016 AMIT KUMAR


# Fill the data bits in the code word
hamming_code[2] = int(data[0])
hamming_code[4] = int(data[1])
hamming_code[5] = int(data[2])
hamming_code[6] = int(data[3])

# Calculate the parity bits


hamming_code[0] = hamming_code[2] ^ hamming_code[4] ^ hamming_code[6]
hamming_code[1] = hamming_code[2] ^ hamming_code[5] ^ hamming_code[6]
hamming_code[3] = hamming_code[4] ^ hamming_code[5] ^ hamming_code[6]

return hamming_code

def hamming_decode(received_code):
# Check if the received code is 7 bits long
if len(received_code) != 7:
raise ValueError("Received code must be 7 bits long")

# Calculate the syndrome bits


syndrome = [0, 0, 0]
syndrome[0] = received_code[0] ^ received_code[2] ^ received_code[4] ^
received_code[6]
syndrome[1] = received_code[1] ^ received_code[2] ^ received_code[5] ^
received_code[6]
syndrome[2] = received_code[3] ^ received_code[4] ^ received_code[5] ^
received_code[6]

# Calculate the error position


error_position = 4 * syndrome[2] + 2 * syndrome[1] + syndrome[0]

# Correct the error if one is found


if error_position > 0:
received_code[error_position - 1] ^= 1

# Extract the data bits


data_bits = [received_code[2], received_code[4], received_code[5],
received_code[6]]

return ''.join(map(str, data_bits))

if __name__ == "__main__":
original_data = "1101" # 4-bit data
hamming_code = hamming_encode(original_data)
received_code = list(hamming_code) # Simulating reception of the Hamming
code

# Simulate noise (flipping a random bit)

CN LAB 2101331520016 AMIT KUMAR


import random
noise_position = random.randint(0, 6)
received_code[noise_position] ^= 1

corrected_data = hamming_decode(received_code)

print(f"Original Data: {original_data}")


print(f"Hamming Code: {''.join(map(str, hamming_code))}")
print(f"Received Code: {''.join(map(str, received_code))}")
print(f"Corrected Data: {corrected_data}")

Input and Output-

Result-

The implementation of Hamming code (7, 4) transmitter and receiver end is done
successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 7
Aim -Implementation of stop and wait protocol in any language like C++ , Java or Python

Theory –
In this case, stop and wait means that the sender provides the recipient’s desired data. The
sender pauses after transferring the data and waits for the receiver to acknowledge his
transmission. The stop and wait protocol, which is a flow control protocol, uses the data link
layer’s flow control functionality. It is a DDL (data-link layer) protocol that is used to send
data through channels with no background noise. It offers unidirectional data transfer, which
means that only one of the two operations, data sending or receiving, can occur concurrently.
Although it offers a flow-control system, there is no error control mechanism. The concept
behind using this frame is that after sending one frame, the sender will wait for an
acknowledgement before sending another one.

For example, if there are 1000 data packets to be sent, then all the 1000 packets cannot be
sent at a time as in Stop and Wait protocol, one packet is sent at a time.

CN LAB 2101331520016 AMIT KUMAR


Code- (with User defined input)

CN LAB 2101331520016 AMIT KUMAR


Input and Output-

Result-

The Implementation of stop and wait protocol is done successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 8

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

Code-

CN LAB 2101331520016 AMIT KUMAR


Input and Output-

Result-

The IP address of the system is found successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 9

Aim -Write a program in java to find the IP address of the any site if
name is given.

Code-

Input and Output-

Result-

The IP address of the site is found successfully.

CN LAB 2101331520016 AMIT KUMAR


Experiment No.- 10

AIM- Introduction to CISCO Packet Tracer. Design Bus, Star, Mesh, Ring Topology and
check the connectivity using ping command.

Software Required: - CISCO Packet Tracer

Theory-
A local area network (LAN) is a collection of devices connected together in one physical
location, such as a building, office, or home. A LAN can be small or large, ranging from
a home network with one user to an enterprise network with thousands of users and
devices in an office or school. Regardless of size, a LAN's single defining characteristic
is that it connects devices that are in a single, limited area. In contrast, a WAN or MAN
covers larger geographic areas. Some WANs and MANs connect many LANs together.
Types of topology: -

1. 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.

4. 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.

CN LAB 2101331520016 AMIT KUMAR


Output-

Bus Topology

Mesh Topology

CN LAB 2101331520016 AMIT KUMAR


Ring Topology

Star Topology

CN LAB 2101331520016 AMIT KUMAR


Result-

The study of CISCO Packet Tracer is completed, and designed the Bus, Star, Mesh, Ring
topology successfully.

CN LAB 2101331520016 AMIT KUMAR

You might also like