From 02d76bcbd5dc49c5c886673544a19986ec991689 Mon Sep 17 00:00:00 2001 From: nibrag Date: Sat, 14 May 2016 13:48:21 +0300 Subject: [PATCH] Added proxy_sockname, proxy_peername, peername properties --- aiosocks/protocols.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/aiosocks/protocols.py b/aiosocks/protocols.py index c5ff3a7..929f3db 100644 --- a/aiosocks/protocols.py +++ b/aiosocks/protocols.py @@ -37,6 +37,8 @@ class BaseSocksProtocol(asyncio.StreamReaderProtocol): self._transport = None self._negotiate_done = False + self._proxy_peername = None + self._proxy_sockname = None if app_protocol_factory: self._app_protocol = app_protocol_factory() @@ -155,6 +157,29 @@ class BaseSocksProtocol(asyncio.StreamReaderProtocol): def app_transport(self): return self._transport + @property + def proxy_sockname(self): + """ + Returns the bound IP address and port number at the proxy. + """ + return self._proxy_sockname + + @property + def proxy_peername(self): + """ + Returns the IP and port number of the proxy. + """ + sock = self._transport.get_extra_info('socket') + return sock.peername if sock else None + + @property + def peername(self): + """ + Returns the IP address and port number of the destination + machine (note: get_proxy_peername returns the proxy) + """ + return self._proxy_peername + class Socks4Protocol(BaseSocksProtocol): def __init__(self, proxy, proxy_auth, dst, app_protocol_factory, waiter,