divya networking
divya networking
GIRLS COLLEGE
SONIPAT
SESSION : {2024-2025}
PRACTICAL FILE
OF
COMPUTER NETWORKS
SUBMITTED BY :- DIVYA
Steps:
• Click on the PC and go to the Desktop tab.
• Click on IP Configuration.
• Set the IP Address and Subnet Mask.
PC1 Configuration:
• IP Address: 192.168.1.2
• Subnet Mask: 255.255.255.0
PC2 Configuration:
• IP Address: 192.168.1.3
• Subnet Mask: 255.255.255.0
PC3 Configuration:
• IP Address: 192.168.1.4
• Subnet Mask: 255.255.255.0
Testing Connectivity:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_DEVICES 5
addDeviceToHub(&hub, &device1);
addDeviceToHub(&hub, &device2);
addDeviceToHub(&hub, &device3);
addDeviceToHub(&hub, &device4);
addDeviceToHub(&hub, &device5);
// Simulate communication
simulateCommunication(&hub);
return 0;
}
OUTPUT:-
class RingTopology:
def __init__(self, node_names):
"""Initialize a ring topology with a list of node names."""
# Create nodes and link them in a circular fashion nodes
= [Node(name) for name in node_names] for i in
range(len(nodes)):
nodes[i].next = nodes[(i + 1) % len(nodes)] # next node
nodes[i].prev = nodes[(i - 1) % len(nodes)] # prev node
self.start_node = nodes[0] # Start from the first node
def start_transmission(self, data):
"""Start data transmission from the first node."""
printf("Starting data transmission with data: {data}")
self.start_node.send_data(data)
# Example usage
if __name__ == "__main__":
# Create a ring topology with nodes A, B, C, D
node_names = ["A", "B", "C", "D"]
ring = RingTopology(node_names)
OUTPUT:-
class MeshNetwork:
def __init__(self, num_devices):
# Initialize the mesh network with 'num_devices'
self.num_devices = num_devices
# Create an adjacency matrix to represent the
network's connections
self.adj_matrix = [[0 for _ in range(num_devices)] for _
in range(num_devices)]
self.create_mesh_topology()
def create_mesh_topology(self):
# In a full mesh, each device is connected to every
other device
for i in range(self.num_devices):
for j in range(self.num_devices):
if i != j:
self.adj_matrix[i][j] = 1 # 1 indicates a direct
connection
def display_network(self):
print("Mesh Topology (Adjacency Matrix):")
for row in self.adj_matrix:
print(row)
def add_device(self):
# Add a new device to the mesh network
self.num_devices += 1
# Expand the adjacency matrix to include the new
device
for row in self.adj_matrix:
row.append(1) # Connect new device to existing
devices
self.adj_matrix.append([1] * self.num_devices) # New
device is connected to all existing devices
def network_summary(self):
# Print summary information about the network
print(f"Number of devices: {self.num_devices}")
print("Direct connections between devices:")
for i in range(self.num_devices):
for j in range(self.num_devices):
if i != j and self.adj_matrix[i][j] == 1:
print(f"Device {i} <-> Device {j}")
# Example usage:
if __name__ == "__main__":
# Create a mesh network with 4 devices
network = MeshNetwork(4)
OUTPUT:-
Mesh Topology (Adjacency Matrix):
[0, 1, 1, 1]
[1, 0, 1, 1]
[1, 1, 0, 1]
[1, 1, 1, 0]
Number of devices: 4
Direct connections between devices:
Device 0 <-> Device 1
Device 0 <-> Device 2
Device 0 <-> Device 3
Device 1 <-> Device 0
Device 1 <-> Device 2
Device 1 <-> Device 3
Device 2 <-> Device 0
Device 2 <-> Device 1
Device 2 <-> Device 3
Device 3 <-> Device 0
Device 3 <-> Device 1
Device 3 <-> Device 2
5.) Write a program to demonstrate
the difference between digital and
analog signals using simple sine
waves and square waves.
import numpy as np
import matplotlib.pyplot as plt
OUTPUT:-
ip a
or
ifconfig -a
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
ip a
2. Install necessary drivers: Some wireless cards
require additional drivers. Use the following
commands to ensure your Wi-Fi drivers are
installed.
ip a
7.) Connect the computer in Local
Area Network.
1. Gather Required Equipment
5. Troubleshooting
subnet mask.
8.) Program to demonstrate
simplex: half- duplex
communication using text- based
examples
class HalfDuplexCommunication:
def __init__(self):
self.sender_data = ""
self.receiver_data = ""
def receive_data(self):
if self.sender_data:
self.receiver_data = self.sender_data
print(f"Receiver: Receiving data -
{self.receiver_data}")
self.sender_data = "" # Clear data after it's
received
else:
print("Receiver: No data to receive.")
if turn == 'quit':
print("Ending communication.")
break
elif turn in ['sender', 'receiver']:
half_duplex.communication_turn(turn)
else:
print("Invalid input! Please enter 'sender', 'receiver',
or 'quit'.")
OUTPUT:-
def receive(self):
with self.lock:
if self.message:
print(f"Received (Simplex): {self.message}")
self.message = None
else:
print("No message to receive.")
def receive(self):
with self.lock:
if self.incoming:
print(f"Received (Full-duplex): {self.incoming}")
self.incoming = None
else:
print("No incoming message.")
def sender():
for i in range(1, 6):
time.sleep(1)
simplex_channel.send(f"Message {i} from Sender")
def receiver():
for _ in range(5):
time.sleep(2)
simplex_channel.receive()
sender_thread = threading.Thread(target=sender)
receiver_thread = threading.Thread(target=receiver)
sender_thread.start()
receiver_thread.start()
sender_thread.join()
receiver_thread.join()
def full_duplex_communication():
full_duplex_channel = FullDuplexChannel()
def sender():
for i in range(1, 6):
time.sleep(1)
full_duplex_channel.send(f"Message {i} from
Sender")
full_duplex_channel.set_incoming_message(f"Reply
to {i} from Receiver")
def receiver():
for _ in range(5):
time.sleep(1.5)
full_duplex_channel.receive()
sender_thread = threading.Thread(target=sender)
receiver_thread = threading.Thread(target=receiver)
sender_thread.start()
receiver_thread.start()
sender_thread.join()
receiver_thread.join()
if __name__ == "__main__":
main()
OUTPUT:-
Physical Installation:
3. Connect power:
o Plug the router into a power source using the
2. Basic Setup:
Router> enable
Router# configure terminal
Router(config)# hostname MyRouter
Router(config)# interface gigabitEthernet 0/0
Router(config-if)# ip address 192.168.1.1 255.255.255.0
Router(config-if)# no shutdown
Router(config-if)# exit
Router(config)# ip route 0.0.0.0 0.0.0.0 [next-hop-IP]
# Set default route
Router(config)# line vty 0 4
Router(config-line)# password [password]
Router(config-line)# login
Router(config-line)# exit
Router(config)# enable secret [enable-password]
Router(config)# end
Router# write memory
3. Verify Configuration:
o show ip interface brief to check the status of
interfaces.
o ping [IP address] to test connectivity.
4. Save Configuration:
o write memory or copy running-config startup-
if start == end:
return path # Found the path
for neighbor in self.adj_list[start]:
if neighbor not in path and not self.is_reserved(start,
neighbor):
# Recursively search for a path
new_path = self.find_path(neighbor, end,
path.copy())
if new_path:
return new_path
if path:
print(f"Path found: {' -> '.join(path)}")
self.reserve_path(path)
return path
else:
print(f"No available path between {start} and
{end}")
return None
if path:
print(f"Transferring data from {start} to {end}...")
print(f"Data transfer successful! Using path: {' ->
'.join(path)}")
self.free_path(path)
print(f"Connection between {start} and {end} is
now terminated.\n")
else:
print("Data transfer failed due to no available
path.\n")
# Example usage
if __name__ == "__main__":
# Initialize the network with nodes
network = CircuitSwitchingNetwork(["A", "B", "C", "D",
"E"])
OUTPUT:-
# Constants
MTU = 8 # Maximum Transmission Unit (max size of
each fragment, in bytes)
HEADER_SIZE = 2 # 2 bytes for the header (identifier +
fragment offset)
PAYLOAD_SIZE = MTU - HEADER_SIZE # Size of the data
in each fragment
def fragment(self):
"""Fragment the packet into smaller pieces if it
exceeds MTU."""
total_size = self.size
offset = 0
fragment_id = random.randint(1000, 9999) # Unique
identifier for this packet
self.fragments.append(PacketFragment(fragment_id,
offset, fragment_data))
offset += PAYLOAD_SIZE
def get_fragments(self):
return self.fragments
def __repr__(self):
return f"Fragment(packet_id={self.packet_id},
offset={self.offset}, data='{self.data}')"
self.received_fragments[fragment.packet_id].append(fragm
ent)
random.shuffle(network.received_fragments[packet.get_fr
agments()[0].packet_id])
if __name__ == "__main__":
main()
OUTPUT:-
def is_valid_ipv4(ip):
# Regular expression to match a valid IPv4 address
pattern = r'^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-
5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-
9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
Example usage:-
Enter an IPv4 address: 192.168.1.1
192.168.1.1 is a valid IPv4 address.
def validate_ipv6(ipv6):
# Regular expression to match valid IPv6 address
# It allows both the full form and the compressed form
with "::"
pattern = re.compile(r'^([0-9a-fA-F]{1,4}:){7}([0-9a-fA-
F]{1,4})$|^([0-9a-fA-F]{1,4}:){1,7}:$|^::([0-9a-fA-
F]{1,4}:){1,7}$|^([0-9a-fA-F]{1,4}:){0,7}([0-9a-fA-
F]{1,4}){0,1}::([0-9a-fA-F]{1,4}){0,7}$')
def main():
ipv6_address = input("Enter an IPv6 address: ")
if validate_ipv6(ipv6_address):
print(f"The IPv6 address '{ipv6_address}' is valid.")
else:
print(f"The IPv6 address '{ipv6_address}' is invalid.")
if __name__ == "__main__":
main()
SAMPLE RUN:-