0% found this document useful (0 votes)
6 views2 pages

Computer Networks Python Practicals

The document contains several Python server implementations using different protocols: UDP for chat and case conversion, TCP for chat and file transfer, and a raw socket for ICMP packet sniffing. Each implementation includes socket creation, binding, and handling of incoming messages or packets. The examples illustrate basic server functionalities such as receiving and sending messages, responding to client requests, and transferring files.

Uploaded by

aktamil13
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)
6 views2 pages

Computer Networks Python Practicals

The document contains several Python server implementations using different protocols: UDP for chat and case conversion, TCP for chat and file transfer, and a raw socket for ICMP packet sniffing. Each implementation includes socket creation, binding, and handling of incoming messages or packets. The examples illustrate basic server functionalities such as receiving and sending messages, responding to client requests, and transferring files.

Uploaded by

aktamil13
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

1.

UDP Chat (Client ends chat) - Server

import socket
s = [Link](socket.AF_INET, socket.SOCK_DGRAM)
[Link](('localhost', 9999))
print("Server ready...")
while True:
data, addr = [Link](1024)
msg = [Link]()
print("Client:", msg)
if [Link]() == 'bye':
break
reply = input("Server: ")
[Link]([Link](), addr)
[Link]()

2. TCP Chat (Server ends chat) - Server

import socket
s = [Link]()
[Link](('localhost', 9999))
[Link](1)
print("Server ready...")
conn, addr = [Link]()
while True:
msg = input("Server: ")
[Link]([Link]())
if [Link]() == 'bye':
break
data = [Link](1024).decode()
print("Client:", data)
[Link]()
[Link]()

3. UDP Case Conversion

import socket
s = [Link](socket.AF_INET, socket.SOCK_DGRAM)
[Link](('localhost', 8888))
print("Server ready...")
while True:
data, addr = [Link](1024)
[Link]([Link]().lower().encode(), addr)

4. ICMP Packet Sniffer

import socket
s = [Link](socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
print("Sniffer running...")
while True:
pkt, addr = [Link](65535)
print("ICMP packet from", addr)
5. TCP File Transfer - Server

import socket
s = [Link]()
[Link](('localhost', 9000))
[Link](1)
conn, addr = [Link]()
filename = [Link](1024).decode()
with open(filename, 'rb') as f:
data = [Link]()
[Link](data)
[Link]()
[Link]()

You might also like