Python 使用代理
Python with Proxy
我想编写一个 python 程序,可以 运行 数据包通过我的本地代理服务器。但提醒一下,我知道请求库,我不想使用它附带的代理选项。它只支持http/https。我希望能够通过 python 中的代理传递我的端口扫描。基本上我想让它 运行 就好像我 运行 带有“proxychains”的脚本一样。有什么办法吗?
处理任意网络协议的代理称为 SOCKS 代理。 pysocks
是可以帮助你的包。来自 documentation:
import socks
s = socks.socksocket() # Same API as socket.socket in the standard lib
s.set_proxy(socks.SOCKS5, "localhost") # SOCKS4 and SOCKS5 use port 1080 by default
# Or
s.set_proxy(socks.SOCKS4, "localhost", 4444)
# Or
s.set_proxy(socks.HTTP, "5.5.5.5", 8888)
# Can be treated identical to a regular socket object
s.connect(("www.somesite.com", 80))
我想编写一个 python 程序,可以 运行 数据包通过我的本地代理服务器。但提醒一下,我知道请求库,我不想使用它附带的代理选项。它只支持http/https。我希望能够通过 python 中的代理传递我的端口扫描。基本上我想让它 运行 就好像我 运行 带有“proxychains”的脚本一样。有什么办法吗?
处理任意网络协议的代理称为 SOCKS 代理。 pysocks
是可以帮助你的包。来自 documentation:
import socks
s = socks.socksocket() # Same API as socket.socket in the standard lib
s.set_proxy(socks.SOCKS5, "localhost") # SOCKS4 and SOCKS5 use port 1080 by default
# Or
s.set_proxy(socks.SOCKS4, "localhost", 4444)
# Or
s.set_proxy(socks.HTTP, "5.5.5.5", 8888)
# Can be treated identical to a regular socket object
s.connect(("www.somesite.com", 80))