0% found this document useful (0 votes)
24 views6 pages

731 Assgn9

Uploaded by

khroudishnoor34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

731 Assgn9

Uploaded by

khroudishnoor34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Computer Network (CSC611)

Assignment - 9

Name: Sagar Mankoti Reg. No.: 731 Roll No.: CSE/21071

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

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[ip] = mac

print(hash_map)

port = 8080
host = "127.0.0.1"

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((host, port))
print("socket binded to", port)

server.listen(2)
print("Socket is listening...")

# Accepting/Establishing connection from client.


conn, addr = server.accept()
print("Got connection from", addr)

while True:
recieved_data = conn.recv(2048)
data = recieved_data.decode()
print("IP recieved from client: ", data)

if recieved_data.decode().lower() == "quit":
break

data = hash_map.get(data, "Not found.")

conn.send(data.encode())

print("Connection closed from client")

conn.close()

# client.py

import socket

port = 8080
portClient = 8081
host = "127.0.0.1"

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


client.bind((host, portClient))
client.connect((host, port))
while True:
data = input("Enter the IP address: ")

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()

print("Connection closed from client.")


client.close()

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 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((host, port))
print("socket binded to", port)

server.listen(2)
print("Socket is listening...")

# Accepting/Establishing connection from client.


conn, addr = server.accept()
print("Got connection from", addr)

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

data = hash_map.get(data, "Not found.")

conn.send(data.encode())
print("Connection closed from client")

conn.close()

# client.py

import socket

port = 8080
portClient = 8081
host = "127.0.0.1"

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


client.bind((host, portClient))
client.connect((host, port))
while True:
data = input("Enter the MAC address: ")

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()

print("Connection closed from client.")


client.close()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy