UDP proxying through SOCKS5 proxies in Python

Is it possible to send UDP datagrams through SOCKS5 proxies in Python using any SOCKS client library? SocksiPy doesn't seem to work, or maybe I'm just wrong. The following code does not work, it tries to connect directly to the recipient:

s = socks.socksocket ( socket.AF_INET, socket.SOCK_DGRAM ) s.setproxy(socks.PROXY_TYPE_SOCKS5,"socks.proxy.lan") s.sendto ( payload, ( ip, port ) ) 

If I change SOCK_DGRAM to SOCK_STREAM , the code also does not work, it does not try to connect anywhere.

+7
source share
2 answers

Have you tried using connect () and send () instead of sendto ()? Judging by the SocksiPy source code, connectionless mode is not implemented.

Edit :

 req = struct.pack('BBB', 0x05, 0x01, 0x00) 

The TCP stream connection (0x01) seems to be hard-coded here. SocksiPy as it will not work.

+2
source

Have you tried this:

 socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "socks.proxy.lan", 8080, True) 

replace port 8080 with port, and "True" - "True" if you want to enable rdns.

If you are using Python version 3 or higher, I suggest you use PySocks, and that will be

 socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, "socks.proxy.lan", 8080, True) 
0
source

All Articles