Computer Networks Pratical
Computer Networks Pratical
Affiliated to Dr. A.P.J Abdul Kalam Technical University, Uttar Pradesh, Lucknow
Department of
CSE - Artificial Intelligence and Machine Learning
LAB FILE
On
Computer Network Lab
(ACSE0552)
(5th Semester)
Session (2024 – 2025)
Submitted by Submitted to
Your Name Mr. Rehan Ali Khan
AIML V C (Asst. Professor)
2201331530*** Dept. of CSE-AIML
Index
S.N Signatu
Experiment Date
. re
To make an UTP cable with RJ-45 connector, and build
1. and test simple network using UTP cable(crossover)and
hub-based network.
Situation Cable
Computer to Computer Crossover Cable
Computer to Hub Straight Through Cable
Hub Port to Hub Port Crossover Cable
Hub uplink to Hub Port Straight Through Cable
Computer to Broadband Router
Straight Through Cable
Port
Computer to Switch Straight Through Cable
Computer to Cable Modem Crossover Cable
Cable Modem to Router Crossover Cable
Hub Uplink to Switch Port Straight Through Cable
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 to hub:
1. Use straight through UTP cable.
2. Insert RJ45 connector to computer's NIC card and other end to HUB.
3. Switch on power of HUB and computer.
if (count == 5):
j += 1
brr[j] = 0
i=k
k += 1
else:
brr[j] = arr[i]
i += 1
j += 1
if __name__ == "__main__":
N = 10
arr = [0,1,0,1,1,0,0,1,1,0]
bitStuffing(N, arr)
Output:
For N=9 and arr=[1,0,1,1,1,1,1,0,1] where there are five consecutive set bits:
For N=10 and arr=[0,1,0,1,1,0,0,1,1,0]where there are no consecutive sequences of five set
bits:
tracert on google.com
import zlib
try:
if isinstance(data, str):
data = data.encode()
return zlib.crc32(data) & 0xffffffff
except Exception as e:
print(f"Error: {e}")
return None
if __name__ == "__main__":
data = "Never have I ever seen a CRC32 checksum"
crc_chksm = crc32(data)
print(f"CRC32: {crc_chksm:#010x}")
Output:
class Packet:
def __init__(self, seq_num, data):
self.seq_num = seq_num
self.data = data
class Sender:
def __init__(self):
self.seq_num = 0
self.timeout = 3
def receive_ack(self):
time.sleep(1)
return True if random.random() < 0.8 else False
def wait_for_ack(self):
start_time = time.time()
while time.time() - start_time < self.timeout:
if self.receive_ack():
return True
return False
class Receiver:
def __init__(self):
self.exp_seq_num = 0
else:
print(f"Receiver: Discarding out of order packet with seq_num: {packet.seq_num}")
return False
def main():
sender = Sender()
receiver = Receiver()
window_size = 1
while True:
if receiver.receive_packet(packet):
receiver.send_ack(True)
break
else:
receiver.send_ack(False)
print()
if __name__ == "__main__":
main()
Output:
def calculate_parity(data):
p1 = data[0]^data[1]^data[3]
p2 = data[0]^data[2]^data[3]
p3 = data[1]^data[2]^data[3]
return p1,p2,p3
def encode(data):
if len(data)!=4:
print("Invalid data")
return
p1,p2,p3 = calculate_parity(data)
encoded_data = [p1,p2,data[0],p3,data[1],data[2],data[3]]
return encoded_data
def main():
data = [1,0,1,1]
encoded_data = encode(data)
print("Encoded 7bit data (with parity): ",encoded_data)
if __name__ == '__main__':
main()
Output:
# Usage
text = "This is a secret message!"
key = 3
Output:
def gen_keypair(p,q):
n = p*q
phi = (p-1)*(q-1)
e = random.randrange(1, phi)
while sympy.gcd(e, phi) != 1:
e = random.randrange(1, phi)
d = sympy.mod_inverse(e, phi)
return ((e, n), (d, n))
# Usage
p = 61
q = 53
public, private = gen_keypair(p, q)
plaintext = "This is a secret message!"
Output:
import java.net.InetAddress;
import java.net.UnknownHostException;
Output:
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;
try {
InetAddress ip = InetAddress.getByName(website);
System.out.println("IP address of " + website + " is: " + ip.getHostAddress());
}
catch (UnknownHostException e) {
System.out.println("Could not find IP address for the given website.");
}
finally {
scanner.close();
}
}
}
Output:
Repeater
a repeater is an electronic device that receives a signal and retransmits it. Repeaters are used
to extend transmissions so that the signal can cover longer distances or be received on the
other side of an obstruction. Some types of repeaters broadcast an identical signal, but alter
its method of transmission, for example, on another frequency or baud rate.
There are several different types of repeaters; a telephone repeater is an amplifier in a
telephone line, an optical repeater is an optoelectronic circuit that amplifies the light beam in
an optical fiber cable; and a radio repeater is a radio receiver and transmitter that retransmits
a radio signal.
A broadcast relay station is a repeater used in broadcast radio and television.
Hub
An Ethernet hub, active hub, network hub, repeater hub, multiport repeater, or simply hub is a
network hardware device for connecting multiple Ethernet devices together and making them
act as a single network segment. It has multiple input/output (I/O) ports, in which a signal
introduced at the input of any port appears at the output of every port except the original
incoming. A hub works at the physical layer. A repeater hub also participates in collision
detection, forwarding a jam signal to all ports if it detects a collision.
Active Hub: These are the hubs which have Passive Hub: These are the hubs which
their own power supply and can clean, collect wiring from nodes and power supply
boost and relay the signal along with the from active hub. These hubs relay signals
network. It serves both as a repeater as onto the network without cleaning and
well as wiring centre. These are used to boosting them and can't be used to extend
extend the maximum distance between the distance between nodes.
nodes.
Bridge
A network bridge is a computer networking device that creates a single, aggregate network
from multiple communication networks or network segments. This function is called network
bridging. Bridging is distinct from routing. Routing allows multiple networks to communicate
independently and yet remain separate, whereas bridging connects two separate networks as
if they were a single network. In the OSI model, bridging is performed in the data link layer. If
one or more segments of the bridged network are wireless, the device is known as a wireless
bridge.
Transparent Bridge: 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 network,
reconfiguration of the stations is unnecessary. These bridges make use of two processes i.e.
bridge forwarding and bridge learning.
Router
A router is a computer and networking device that forwards data packets between computer
networks, including internetworks such as the global Internet. A router is connected to two or
more data lines from different IP networks. When a data packet comes in on a line, 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. Data packets are forwarded from one router to another
through an internetwork until it reaches its destination node.
The most familiar type of IP routers are home and small office routers that forward IP packets
between the home computers and the Internet. More sophisticated routers, such as enterprise
routers, connect large business or ISP networks to powerful core routers that forward data at
high speed along the optical fiber lines of the Internet backbone.
Gateway
A gateway is a piece of networking hardware or software used in telecommunications
networks that allows data to flow from one discrete network to another. Gateways are distinct
from routers or switches in that they communicate using more than one protocol to connect
multiple networks and can operate at any of the seven layers of the OSI model.
The term gateway can also loosely refer to a computer or computer program configured to
perform the tasks of a gateway, such as a default gateway or router, and in the case of HTTP,
gateway is also often used as a synonym for reverse proxy. It can also refer to a device
installed in homes that combines router and modem functionality into one device, used by
ISPs, also called a residential gateway.
NIC
A network interface controller (NIC, also known as a network interface card, network adapter,
LAN adapter and physical network interface) is a computer hardware component that
connects a computer to a computer network.
Early network interface controllers were commonly implemented on expansion cards that
plugged into a computer bus. The low cost and ubiquity of the Ethernet standard means that
most newer computers have a network interface built into the motherboard, or is contained
into a USB-connected dongle.
Modern network interface controllers offer advanced features such as interrupt and DMA
interfaces to the host processors, support for multiple receive and transmit queues,
partitioning into multiple logical interfaces, and on-controller network traffic processing such
as the TCP offload engine.
Topologies:
Design of different Topologies and check their connectivity using ping command.
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.
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.
Steps:
1. Click on the switch in Packet Tracer.
2. Go to the CLI tab.
3. Enter configuration mode
4. Then:
Switch> enable
Switch# configure terminal
Switch(config)# hostname MySwitch
MySwitch(config)# interface vlan 1
MySwitch(config-if)# ip address 192.168.0.113 255.255.255.0
MySwitch(config-if)# no shutdown
MySwitch(config-if)# exit
MySwitch(config)# ip default-gateway 192.168.1.1
MySwitch(config)# line console 0
MySwitch(config-line)# password cisco
MySwitch(config-line)# login
MySwitch(config-line)# exit
MySwitch(config)# line vty 0 4
MySwitch(config-line)# password cisco
MySwitch(config-line)# login
MySwitch(config-line)# exit
MySwitch(config)# ip domain-name example.com
MySwitch(config)# crypto key generate rsa
MySwitch(config)# 1024
MySwitch(config)# line vty 0 4
MySwitch(config-line)# transport input ssh
MySwitch(config-line)# exit