|
@@ -20,7 +20,6 @@ class SocksProtocol(asyncio.StreamReaderProtocol): |
|
|
|
|
|
|
|
|
self._loop = loop or asyncio.get_event_loop() |
|
|
self._loop = loop or asyncio.get_event_loop() |
|
|
self._transport = None |
|
|
self._transport = None |
|
|
|
|
|
|
|
|
self._negotiate_done = None |
|
|
self._negotiate_done = None |
|
|
|
|
|
|
|
|
reader = asyncio.StreamReader(loop=self._loop) |
|
|
reader = asyncio.StreamReader(loop=self._loop) |
|
@@ -61,23 +60,22 @@ class SocksProtocol(asyncio.StreamReaderProtocol): |
|
|
raise OSError('getaddrinfo() returned empty list') |
|
|
raise OSError('getaddrinfo() returned empty list') |
|
|
return infos[0][0], infos[0][4][0] |
|
|
return infos[0][0], infos[0][4][0] |
|
|
|
|
|
|
|
|
async def negotiate_done(self): |
|
|
|
|
|
return await self._negotiate_done |
|
|
|
|
|
|
|
|
def negotiate_done(self): |
|
|
|
|
|
return self._negotiate_done |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Socks4Protocol(SocksProtocol): |
|
|
class Socks4Protocol(SocksProtocol): |
|
|
def __init__(self, proxy, proxy_auth, dst, remote_resolve=True, loop=None): |
|
|
def __init__(self, proxy, proxy_auth, dst, remote_resolve=True, loop=None): |
|
|
|
|
|
proxy_auth = proxy_auth or Socks4Auth('') |
|
|
|
|
|
|
|
|
if not isinstance(proxy, Socks4Addr): |
|
|
if not isinstance(proxy, Socks4Addr): |
|
|
raise ValueError('Invalid proxy format') |
|
|
raise ValueError('Invalid proxy format') |
|
|
|
|
|
|
|
|
if proxy_auth is not None and not isinstance(proxy_auth, Socks4Auth): |
|
|
|
|
|
|
|
|
if not isinstance(proxy_auth, Socks4Auth): |
|
|
raise ValueError('Invalid proxy_auth format') |
|
|
raise ValueError('Invalid proxy_auth format') |
|
|
|
|
|
|
|
|
super().__init__(proxy, proxy_auth, dst, remote_resolve, loop) |
|
|
super().__init__(proxy, proxy_auth, dst, remote_resolve, loop) |
|
|
|
|
|
|
|
|
if proxy_auth is None: |
|
|
|
|
|
self._auth = Socks4Auth('') |
|
|
|
|
|
|
|
|
|
|
|
async def socks_request(self, cmd): |
|
|
async def socks_request(self, cmd): |
|
|
# prepare destination addr/port |
|
|
# prepare destination addr/port |
|
|
host, port = self._dst_host, self._dst_port |
|
|
host, port = self._dst_host, self._dst_port |
|
@@ -114,17 +112,16 @@ class Socks4Protocol(SocksProtocol): |
|
|
|
|
|
|
|
|
class Socks5Protocol(SocksProtocol): |
|
|
class Socks5Protocol(SocksProtocol): |
|
|
def __init__(self, proxy, proxy_auth, dst, remote_resolve=True, loop=None): |
|
|
def __init__(self, proxy, proxy_auth, dst, remote_resolve=True, loop=None): |
|
|
|
|
|
proxy_auth = proxy_auth or Socks5Auth('', '') |
|
|
|
|
|
|
|
|
if not isinstance(proxy, Socks5Addr): |
|
|
if not isinstance(proxy, Socks5Addr): |
|
|
raise ValueError('Invalid proxy format') |
|
|
raise ValueError('Invalid proxy format') |
|
|
|
|
|
|
|
|
if proxy_auth is not None and not isinstance(proxy_auth, Socks5Auth): |
|
|
|
|
|
|
|
|
if not isinstance(proxy_auth, Socks5Auth): |
|
|
raise ValueError('Invalid proxy_auth format') |
|
|
raise ValueError('Invalid proxy_auth format') |
|
|
|
|
|
|
|
|
super().__init__(proxy, proxy_auth, dst, remote_resolve, loop) |
|
|
super().__init__(proxy, proxy_auth, dst, remote_resolve, loop) |
|
|
|
|
|
|
|
|
if proxy_auth is None: |
|
|
|
|
|
self._auth = Socks5Auth('', '') |
|
|
|
|
|
|
|
|
|
|
|
async def socks_request(self, cmd): |
|
|
async def socks_request(self, cmd): |
|
|
# send available auth methods |
|
|
# send available auth methods |
|
|
if self._auth.login and self._auth.password: |
|
|
if self._auth.login and self._auth.password: |
|
|