Lab Mid Networks (1) - 1
Lab Mid Networks (1) - 1
Mid Report
for
Computer Networks
By
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.
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).
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).
Given the base network 192.168.41.0/27, let’s create the subnets according to the required sizes.
Step 3:
a. The name of the first router R1 is Salar1 and the name of the second router R2 is Salar2.
c. To verify the operational status of interfaces, use the command: “show ip interface brief”
For Salar1:
For Salar2:
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).
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
Salar2:
For Student:
Salar1:
Salar2:
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: