0% found this document useful (0 votes)
11 views

Lab Mid Networks (1) - 1

Lab midterm computer networks

Uploaded by

waliurrehman446
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lab Mid Networks (1) - 1

Lab midterm computer networks

Uploaded by

waliurrehman446
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

COMSATS University Islamabad (CUI)

Mid Report
for

Computer Networks

By

Umer Javed SP23/BDS/052

SIR MUHAMAAD AHSAN

Bachelor of Science in Data Science (2023-


2026)
Question no. 1:
Task: Simple TCP Client-Server Program in Python (Please print the program code)

Answer:
Client-side Program:
import socket
import sys
def create_socket_connection(host, port):
"""Create and return a socket connection to the server."""
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((host, port))
return client_socket
except socket.error as error:
print(f"Error connecting to the server: {error}")
sys.exit(1)
def send_message(socket, message):
"""Send a message to the server and receive the response."""
try:
socket.sendall(message)
response = socket.recv(1024)
return response
except socket.error as error:
print(f"Error during message transmission: {error}")
sys.exit(1)
def main():
if len(sys.argv) != 2:
print("Usage: python echo-client.py <message>")
sys.exit(1)
message = sys.argv[1].encode("utf-8") # Encoding the message to bytes
host = "127.0.0.1" # The server's IP address (localhost)
port = 65432 # The port used by the server
# Create the socket connection and send the message
with create_socket_connection(host, port) as client_socket:
response = send_message(client_socket, message)
print(f"Received: {response.decode('utf-8')}") # Decoding the response to a string
if __name__ == "__main__":
main()
Server-side Program:
import socket
def create_server_socket(host, port):
"""Create and bind a server socket to the given host and port."""
try:
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((host, port))
server_socket.listen()
print(f"Server is listening on {host}:{port}")
return server_socket
except socket.error as error:
print(f"Error creating server socket: {error}")
exit(1)
def handle_client_connection(connection):
"""Handle communication with the connected client."""
with connection:
print(f"Connected by {connection.getpeername()}")
while True:
data = connection.recv(1024)
if not data:
break
# Process and send the response to the client
response = data + b" Response from server."
connection.sendall(response)
def main():
host = "127.0.0.1" # Localhost address
port = 65432 # Port to listen on
# Set up the server socket and accept incoming connections
with create_server_socket(host, port) as server_socket:
while True:
client_connection, client_address = server_socket.accept()
handle_client_connection(client_connection)
if __name__ == "__main__":
main()
Question No. 2:
LAB: Configuring DHCP (Dynamic Host Configuration Protocol) (Please print all the
configurations and outputs after completing the lab on Packet Tracer).
Answer:
Step 1: Determine Subnet Sizes

For each subnet, we need to allocate enough IP addresses to meet the host requirements, plus some
additional ones for network and broadcast addresses.

First Subnet (22 Hosts)

 To support 22 hosts, we need at least 26 IP addresses (24 usable + 2 for network and broadcast).

 The smallest subnet mask that can accommodate 26 IPs is /27 (which gives 32 IPs).

o Subnet Mask: 255.255.255.224 (or /27).

o IP Range: 32 IP addresses (30 usable).

Second Subnet (54 Hosts)

 To support 54 hosts, we need at least 56 IP addresses (54 usable + 2 for network and broadcast).

 The smallest subnet mask that can accommodate 56 IPs is /26 (which gives 64 IPs).

o Subnet Mask: 255.255.255.192 (or /26).

o IP Range: 64 IP addresses (62 usable).

Step 2: Calculate the Subnets

Given the base network 192.168.41.0/27, let’s create the subnets according to the required sizes.

First Subnet (at R1): /27 Subnet

1. Network ID: 192.168.41.0/27

2. Subnet Mask: 255.255.255.224

3. Range: 192.168.41.0 - 192.168.41.31

4. First Usable IP: 192.168.41.1

5. Last Usable IP: 192.168.41.30

6. Broadcast Address: 192.168.41.31

Second Subnet (at R2): /26 Subnet

1. Network ID: 192.168.41.32/26

2. Subnet Mask: 255.255.255.192


3. Range: 192.168.41.32 - 192.168.41.95

4. First Usable IP: 192.168.41.33

5. Last Usable IP: 192.168.41.94

6. Broadcast Address: 192.168.41.95

Step 2: Cable the network as shown in the topology.

Step 3:
a. The name of the first router R1 is Salar1 and the name of the second router R2 is Salar2.

b. To disable DNS lookup, use the command: “no ip domain-lookup”


For Salar1:
For Salar2:

c. To verify the operational status of interfaces, use the command: “show ip interface brief”

For Salar1:

For Salar2:

Step 4: Configure DHCP on both Routers.

For Salar1:
For Salar2:

Step 5: Configure G0/0/0 on Routers 1 & 2 and make sure interfaces are properly
configured and UP. Choose any /30 subnet.

For Salar 1:

For Salar 2:
Question No. 3
LAB: INTER VLAN ROUTING (Please print all the configurations and outputs after completing
the lab on Packet Tracer).

Step 1: Cable the network as shown in the topology.

Step 2: Configure basic settings for each switch.


For Salar1:

For Salar2:
Step 3: Configure PC hosts.
o PC-A
PC-A> configure terminal
PC-A(config)# ip address 192.168.10.3 255.255.255.0
PC-A(config)# ip default-gateway 192.168.10.1

o For PC-B:
PC-B> configure terminal
PC-B(config)# ip address 192.168.20.3 255.255.255.0
PC-B(config)# ip default-gateway 192.168.20

Step 4: Assign VLANs to the correct switch interfaces.


For Teacher VLAN:
Salar1:

Salar2:
For Student:
Salar1:

Salar2:

Part 3: Configure an 802.1Q Trunk Between the Switches


Step 1: Manually configure trunk interface F0/1 on switch Salar1 and Salar2.
For Salar1:
For Salar2:

Step 2: Manually configure Salar1’s trunk interface F0/5


a. Salar1(config)# interface FastEthernet0/5
Salar1(config-if)# switchport mode trunk
Salar1 (config-if)# switchport trunk allowed vlan 10,20
Salar1 (config-if)# exit
b. Salar1# copy running-config startup-config
Destination filename [startup-config]?
Building configuration...
[OK]
c. Salar1# show interfaces trunk
Part 4: Configure Inter-VLAN Routing on the Router
Step 1: Configure the router.
a. Salar(config)# interface gigabitethernet0/0/1
Salar (config-if)# no shutdown
b. Salar (config)# interface gigabitethernet0/0/0.10
Salar (config-subif)# encapsulation dot1Q 10
Salar (config-subif)# ip address 192.168.10.1 255.255.255.0
Salar (config-subif)# exit
Salar (config)# interface gigabitethernet0/0/0.20
Salar (config-subif)# encapsulation dot1Q 20
Salar (config-subif)# ip address 192.168.20.1 255.255.255.0
Salar (config-subif)# exit

c. Ping from PC A to PC B
1. PC-A> ping 192.168.10.3
Step 2: Complete the following test from PC-B
The potential intermediate IP addresses shown in the results of the tracert command from PC-B
to PC-A could be:

You might also like