将 SocksiPy 与 SSL 结合使用 [英] Using SocksiPy with SSL

查看:38
本文介绍了将 SocksiPy 与 SSL 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 SocksIPy 与 ssl 模块(来自 stdlib)一起使用来获取站点的远程证书,但 SocksIPy 无法使用 ssl.

I'm trying to use SocksIPy with ssl module (from stdlib) to grab a site's remote certificate but SocksIPy won't play with ssl.

下面的代码将连接到 check.torproject.org 并声明我们没有使用 Tor(意味着 SocksIPy 不工作)(不好).

The below code will connect to check.torproject.org and state we are not using Tor (meaning SocksIPy is not working) (bad).

不确定 SocksIPy 是否是最好的解决方案,但我找不到任何其他方法来代理原始套接字(或获取 pycurl/urllib2 以使用 SOCKS 代理并提供 SSL 证书!).

Not sure if SocksIPy is the best solution for this but I haven't been able to find any other way to proxify a raw socket (or get pycurl/urllib2 to use SOCKS proxies and give SSL certs!).

澄清一下,我的问题是套接字没有被代理.我想通过我选择的代理获取 ssl 证书,但没有发生.

To clarify, my issue is that the socket is not being proxied. I'd like to get the ssl certificate with a proxy of my choosing, that's not happening.

现在看来,我可以拥有代理或 SSL,但不能同时拥有.帮助!

Seems right now, I can either have proxy or SSL but not both. Help!

import socks
import ssl

s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)

ss = ssl.wrap_socket(s)
ss.connect(('check.torproject.org', 443))
ss.write("""GET / HTTP/1.0\r
Host: check.torproject.org\r\n\r\n""")

# print ss.getpeercert()
print ss.read(), ss.read(), ss.read()
ss.close()

推荐答案

我在运行 tcpdump 时测试了这段代码,所以它应该可以工作.

I have tested this code while running tcpdump so it should work.

import socks
import ssl

s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5,"127.0.0.1",port=9050)
s.connect(('83.94.121.246', 443))
ss = ssl.wrap_socket(s)
print ss.send("hello")
ss.close()

我没有查看 ssl.py,但我猜你必须在socks 对象而不是ssl 对象上调用connect.

I didn't review the ssl.py but I guess you have to call connect on the socks object and not the ssl object.

这篇关于将 SocksiPy 与 SSL 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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