731 Assgn9
731 Assgn9
Assignment - 9
Q1. Write a TCP/UDP socket program (in C/C++/Java/Python) to establish a connection between
client and server. The server should act as a network device maintaining an ARP table.
Implement ARP request and reply functionality. Display appropriate messages indicating the
ARP request and response. Test your program with multiple clients requesting ARP resolution
for different IP addresses.
# server.py
import os
import re
import socket
hash_map = {}
for line in data:
ip = (re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line)[0])
mac = (re.findall(r'(?:[0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}', line)[0])
hash_map[ip] = mac
print(hash_map)
port = 8080
host = "127.0.0.1"
server.listen(2)
print("Socket is listening...")
while True:
recieved_data = conn.recv(2048)
data = recieved_data.decode()
print("IP recieved from client: ", data)
if recieved_data.decode().lower() == "quit":
break
conn.send(data.encode())
conn.close()
# client.py
import socket
port = 8080
portClient = 8081
host = "127.0.0.1"
if data.lower() == "quit":
client.send(data.encode())
break
client.send(data.encode())
recieved_data = client.recv(2048).decode()
print(f"MAC address recieved from server: {recieved_data}")
print()
Q2. Write a TCP/UDP socket program (in C/C++/Java/Python) to establish a connection between
client and server. The server should act as a network device maintaining a RARP table mapping
MAC addresses to IP addresses. Implement RARP request and reply functionality. Display
appropriate messages indicating the RARP request and response. Test your program with
multiple clients requesting RARP resolution for different MAC addresses.
# server.py
import os
import re
import socket
with os.popen('arp -a') as f:
data = f.readlines()
hash_map = {}
for line in data:
ip = (re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line)[0])
mac = (re.findall(r'(?:[0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}', line)[0])
hash_map[mac] = ip
print(hash_map)
port = 8080
host = "127.0.0.1"
server.listen(2)
print("Socket is listening...")
while True:
recieved_data = conn.recv(2048)
data = recieved_data.decode()
print("MAC address recieved from client: ", data)
if recieved_data.decode().lower() == "quit":
break
conn.send(data.encode())
print("Connection closed from client")
conn.close()
# client.py
import socket
port = 8080
portClient = 8081
host = "127.0.0.1"
if data.lower() == "quit":
client.send(data.encode())
break
client.send(data.encode())
recieved_data = client.recv(2048).decode()
print(f"IP address recieved from server: {recieved_data}")
print()