From cf1437491a20d53e18ebb47c9fd26b113efeeb06 Mon Sep 17 00:00:00 2001 From: nibrag Date: Mon, 9 May 2016 19:18:50 +0300 Subject: [PATCH] Do not include domain if proxy.host is ip --- aiosocks/protocols.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aiosocks/protocols.py b/aiosocks/protocols.py index c7c8135..60d6e1d 100644 --- a/aiosocks/protocols.py +++ b/aiosocks/protocols.py @@ -80,11 +80,14 @@ class Socks4Protocol(SocksProtocol): # prepare destination addr/port host, port = self._dst_host, self._dst_port port_bytes = struct.pack(b'>H', port) + include_hostname = False + try: host_bytes = socket.inet_aton(host) except socket.error: if self._remote_resolve: host_bytes = bytes([c.NULL, c.NULL, c.NULL, 0x01]) + include_hostname = True else: # it's not an IP number, so it's probably a DNS name. family, host = await self._get_dst_addr() @@ -92,7 +95,7 @@ class Socks4Protocol(SocksProtocol): # build and send connect command req = [c.SOCKS_VER4, cmd, port_bytes, host_bytes, self._auth.login, c.NULL] - if self._remote_resolve: + if include_hostname: req += [self._dst_host.encode('idna'), c.NULL] self.write_request(req)