简体   繁体   English

在Python中使用SOCKS5代理代理UDP

[英]Proxying UDP over SOCKS5 proxy in Python

Is it possible to send UDP datagrams over SOCKS5 proxy in Python using any SOCKS client lib? 是否可以使用任何SOCKS客户端lib在Python中通过SOCKS5代理发送UDP数据报? SocksiPy does not seem to work or maybe I am just using it wrong. SocksiPy似乎没有用,或者我只是错误地使用它。 The following code does not work, it tries to connect to the destination directly: 以下代码不起作用,它尝试直接连接到目标:

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 does not work either, it does not try to connect anywhere then. 如果我将SOCK_DGRAM更改为SOCK_STREAM则代码也不起作用,它不会尝试在任何地方连接。

Have you tried to use connect() and send() instead of sendto()? 您是否尝试使用connect()和send()而不是sendto()? Judging from the SocksiPy source code, connectionless mode isn't implemented. 从SocksiPy源代码来看,没有实现无连接模式。

Edit : 编辑

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

TCP stream connection (0x01) seems to be hardcoded here. TCP流连接(0x01)似乎在这里是硬编码的。 SocksiPy as it is won't work. SocksiPy因为它不会起作用。

Have you tried this: 你试过这个:

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

replace 8080 with the port and "True" is True if you want rdns enabled. 用端口替换8080,如果要启用rdns,则“True”为True。

If you are using Python version 3 and above i suggest you use PySocks and it would be 如果您使用的是Python 3及更高版本,我建议您使用PySocks,它就是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM