Python Forum
Socks 5 Proxy Server For UDP ASSOCIATE - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Socks 5 Proxy Server For UDP ASSOCIATE (/thread-39841.html)



Socks 5 Proxy Server For UDP ASSOCIATE - ankit - Apr-21-2023

I want Help in Developing Socks5 Based Proxy Server For TCP and UDP Support.
I am able to build it for TCP but facing issue for UDP....


RE: Socks 5 Proxy Server For UDP ASSOCIATE - margaretmossman - Jun-13-2023

To build a Socks5 based proxy server for TCP and UDP support, you can use the SOCKS5 protocol1. The SOCKS5 protocol provides support for UDP. A client wishing to relay UDP packets through a SOCKS5 server must open a TCP connection to the SOCKS5 server and send a UDP ASSOCIATE request. The server then returns the address and port where it must send UDP packets to be relayed.

Here is an example of how to create a Socks 5 proxy server for TCP and UDP in Python 3:

# Create new UDP socket and send/receive data
udp_sock = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
udp_sock.connect ((target_addr, int.from_bytes (target_port, 'big')))
while True:
    data, addr = udp_sock.recvfrom (4096)
    data = handle_udp (udp_sock, data)
    sock.sendto (data, addr)