0% found this document useful (0 votes)
10 views51 pages

Cs3591 CN Lab Manual

The document outlines simulations for DNS using UDP sockets, Distance Vector/Link State Routing algorithms, and error detection using Cyclic Redundancy Check (CRC). Each section includes the aim, required software, algorithms, and sample code demonstrating the implementation of these concepts. The results indicate successful simulations for each of the described networking techniques.

Uploaded by

ruthraelumalai
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)
10 views51 pages

Cs3591 CN Lab Manual

The document outlines simulations for DNS using UDP sockets, Distance Vector/Link State Routing algorithms, and error detection using Cyclic Redundancy Check (CRC). Each section includes the aim, required software, algorithms, and sample code demonstrating the implementation of these concepts. The results indicate successful simulations for each of the described networking techniques.

Uploaded by

ruthraelumalai
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/ 51

EX NO: 5 SIMULATION OF DNS USING UDP SOCKETS

DATE:

Aim:

To simulate a Domain Name System (DNS) using UDP sockets, where a client sends a
domain name and the server responds with the corresponding IP address.

Apparatus / Software Required:

S. No Component Specification / Software


1 System / PC Windows / Linux OS
2 Programming Language Python / C / Java
3 Networking Protocol UDP (User Datagram
Protocol)
Algorithm:

 Server (DNS Server):


 Start the server and create a UDP socket.
 Bind the socket to a specific port.
 Wait for the client’s request (domain name).
 On receiving a domain name, search for it in the DNS database.
 If found, return the IP address; else return 'Domain not found'.
 Repeat for all incoming requests.
 Client (DNS Client):
 Create a UDP socket.
 Send a domain name query to the server.
 Receive the response (IP address / error).
 Display the result.
 Continue until user chooses to exit.

Program:

Server:
import socket
dns_table = {
"www.google.com": "142.250.183.196",
"www.yahoo.com": "98.137.11.163",
"www.github.com": "140.82.114.3"
}

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


server.bind(("localhost", 8080))
print("DNS Server running...")
while True:
data, addr = server.recvfrom(1024)
domain = data.decode()
print(f"Query from Client: {domain}")
ip = dns_table.get(domain, "Domain not found")
server.sendto(ip.encode(), addr)
Client:
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
domain = input("Enter domain name (or 'exit' to quit): ")
if domain.lower() == "exit":
break
client.sendto(domain.encode(), ("localhost", 8080))
data, _ = client.recvfrom(1024)
print("Server Response:", data.decode())

client.close()
Sample Output:
Client Side:
Enter domain name (or 'exit' to quit): www.google.com
Server Response: 142.250.183.196
Enter domain name (or 'exit' to quit): www.unknown.com
Server Response: Domain not found

Server Side:
DNS Server running...
Query from Client: www.google.com
Query from Client: www.unknown.com

Result:
The simulation of DNS using UDP sockets was successfully implemented.
EX NO: 9 SIMULATION OF DISTANCE VECTOR / LINK STATE ROUTING ALGORITHM
DATE:
DATE:
Aim:
To simulate routing algorithms such as Distance Vector Routing and Link State Routing
for path determination in computer networks.
Apparatus / Software Required:
S. No Component Specification / Software
1 System / PC Windows / Linux OS
2 Programming Language Python / C / Java
3 Networking Concept Routing Algorithms
(DVR/LSR)
Algorithm:
 Distance Vector Routing Algorithm:
 Initialize distance table for each router.
 Exchange distance vectors with neighbors.
 Update routing table based on shortest path.
 Repeat until convergence.
 Link State Routing Algorithm:
 Each router discovers neighbors and measures link costs.
 Routers flood link state packets to all others.
 Each router constructs a complete topology map.
 Use Dijkstra’s algorithm to compute shortest path to all destinations.
Program:
Server:
# Python simulation of Distance Vector Routing
nodes = ["A", "B", "C"]
graph = {
"A": {"B": 1, "C": 4},
"B": {"A": 1, "C": 2},
"C": {"A": 4, "B": 2}
}

def distance_vector(graph, start):


dist = {node: float("inf") for node in graph}
dist[start] = 0
visited = set()
while len(visited) < len(graph):
min_node = min((n for n in graph if n not in visited), key=lambda x: dist[x])
visited.add(min_node)
for neighbor, cost in graph[min_node].items():
if dist[min_node] + cost < dist[neighbor]:
dist[neighbor] = dist[min_node] + cost
return dist

print("Distance Vector from A:", distance_vector(graph, "A"))


Sample Output:
Output:
Distance Vector from A: {'A': 0, 'B': 1, 'C': 3}

Result:
The simulation of Distance Vector and Link State Routing was successfully
implemented.
EX NO: 10 SIMULATION OF AN ERROR CORRECTION CODE (LIKE CRC)
DATE:
DATE:

Aim:

To simulate error detection using Cyclic Redundancy Check (CRC) technique.

Apparatus / Software Required:

S. No Component Specification / Software


1 System / PC Windows / Linux OS
2 Programming Language Python / C / Java
3 Networking Concept Error Detection (CRC)
Algorithm:

CRC Algorithm:

 Append (n-1) zeros to the data (where n = length of divisor).


 Divide the appended data by the generator polynomial using XOR.
 The remainder is the CRC checksum.
 At receiver side, divide the received data by the same divisor.
 If remainder = 0, no error; else error detected.

Program:

Server:
# Python simulation of CRC
def xor(a, b):
result = []
for i in range(1, len(b)):
result.append('0' if a[i] == b[i] else '1')
return ''.join(result)

def mod2div(dividend, divisor):


pick = len(divisor)
tmp = dividend[0:pick]
while pick < len(dividend):
if tmp[0] == '1':
tmp = xor(divisor, tmp) + dividend[pick]
else:
tmp = xor('0'*pick, tmp) + dividend[pick]
pick += 1
if tmp[0] == '1':
tmp = xor(divisor, tmp)
else:
tmp = xor('0'*pick, tmp)
return tmp

data = "1101011011"
key = "10011"
appended_data = data + '0'*(len(key)-1)
remainder = mod2div(appended_data, key)
codeword = data + remainder
print("Data:", data)
print("Key:", key)
print("Codeword:", codeword)
Sample Output:

Output:
Data: 1101011011
Key: 10011
Codeword: 11010110111110

Result:

The simulation of error detection using CRC was successfully implemented.

You might also like