如何使用asyncio通过SOCKS5获得TCP响应?

时间:2018-09-03 22:38:30

标签: python-3.x python-asyncio socks python-3.7

我想使用SOCKS5代理执行tcp请求。我在Ubuntu 16.04上使用 IF(((SUBSTR(address,i,1) in (CHAR(10) ,CHAR(13))) AND (SUBSTR(address,i+1,1) in (CHAR(10) ,CHAR(13))) ) ) THEN set address = INSERT(address,i,1,''); ELSE set i= i+1; END IF; asyncio软件包以及python3.7版本。 这是我的代码

aiosocks

但是我有下一个错误:

ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

future_connection = aiosocks.open_connection(
proxy=aiosocks.Socks5Addr("127.0.0.1", 1080),
proxy_auth=aiosocks.Socks5Auth("login", "password"),
dst=("192.168.0.101", 8443),
ssl=ssl_context,
remote_resolve=True)

reader, writer = await asyncio.wait_for(future_connection, timeout=self.connection_timeout)
writer.write(b"Hello Message\r\n\r\n")

tcp_data = await asyncio.wait_for(reader.read(1024000), timeout=self.request_timeout)

我也尝试升级我的openssl软件包,我的当前版本是

SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x7fd923f54c18
transport: <_SelectorSocketTransport fd=6 read=polling write=<idle, bufsize=0
Traceback (most recent call last):
  File "/usr/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/lib/python3.7/asyncio/sslproto.py", line 200, in feed_ssldata
    chunk = self._sslobj.read(self.max_size)
  File "/usr/lib/python3.7/ssl.py", line 707, in read
    v = self._sslobj.read(len)
ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:2460)

没有python3.7 -c "import ssl; print( ssl.OPENSSL_VERSION)" OpenSSL 1.0.2g 1 Mar 2016 的代码也很好用

aiosocks

但是我尝试了多个具有相同错误的代理服务器。

由于存在此错误https://bugs.python.org/issue23749,python3.6上的ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE future_connection = asyncio.open_connection("192.168.0.101", 8443, ssl=ssl_context) reader, writer = await asyncio.wait_for(future_connection, timeout=self.connection_timeout) writer.write(b"Hello Message\r\n\r\n") tcp_data = await asyncio.wait_for(reader.read(1024000), timeout=self.request_timeout) 也无法用于SSL连接。

那么,如何使用aiosocks通过SOCKS5获得TCP响应?

0 个答案:

没有答案