在 Python 中通过 SOCKS5 代理代理 UDP [英] Proxying UDP over SOCKS5 proxy in Python

查看:179
本文介绍了在 Python 中通过 SOCKS5 代理代理 UDP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用任何 SOCKS 客户端库通过 Python 中的 SOCKS5 代理发送 UDP 数据报?SocksiPy 似乎不起作用,或者我可能只是使用错误.以下代码不起作用,它尝试直接连接到目的地:

Is it possible to send UDP datagrams over SOCKS5 proxy in Python using any SOCKS client lib? SocksiPy does not seem to work or maybe I am just using it wrong. 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 ) )

如果我将 SOCK_DGRAM 更改为 SOCK_STREAM 代码也不起作用,它不会尝试连接到任何地方.

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

推荐答案

您是否尝试过使用 connect() 和 send() 而不是 sendto()?从 SocksiPy 源代码来看,没有实现无连接模式.

Have you tried to use connect() and send() instead of sendto()? Judging from the SocksiPy source code, connectionless mode isn't implemented.

编辑:

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

TCP 流连接 (0x01) 在这里似乎是硬编码的.SocksiPy 无法正常工作.

TCP stream connection (0x01) seems to be hardcoded here. SocksiPy as it is won't work.

这篇关于在 Python 中通过 SOCKS5 代理代理 UDP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆