mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 20:59:29 +00:00
Fix ipv6 with ipv4 proxies
This commit is contained in:
parent
6a89c7ea02
commit
28abcaac50
@ -34,24 +34,33 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class TCP(socks.socksocket):
|
class TCP(socks.socksocket):
|
||||||
def __init__(self, ipv6: bool, proxy: dict):
|
def __init__(self, ipv6: bool, proxy: dict):
|
||||||
super().__init__(family=socket.AF_INET6 if ipv6 else socket.AF_INET)
|
if proxy.get("enabled", False):
|
||||||
|
hostname = proxy.get("hostname", None)
|
||||||
|
port = proxy.get("port", None)
|
||||||
|
|
||||||
self.settimeout(10)
|
try:
|
||||||
self.proxy_enabled = proxy.get("enabled", False)
|
socket.inet_aton(hostname)
|
||||||
|
except socket.error:
|
||||||
|
super().__init__(socket.AF_INET6)
|
||||||
|
else:
|
||||||
|
super().__init__(socket.AF_INET)
|
||||||
|
|
||||||
if proxy and self.proxy_enabled:
|
|
||||||
self.set_proxy(
|
self.set_proxy(
|
||||||
proxy_type=socks.SOCKS5,
|
proxy_type=socks.SOCKS5,
|
||||||
addr=proxy.get("hostname", None),
|
addr=hostname,
|
||||||
port=proxy.get("port", None),
|
port=port,
|
||||||
username=proxy.get("username", None),
|
username=proxy.get("username", None),
|
||||||
password=proxy.get("password", None)
|
password=proxy.get("password", None)
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info("Using proxy {}:{}".format(
|
log.info("Using proxy {}:{}".format(hostname, port))
|
||||||
proxy.get("hostname", None),
|
else:
|
||||||
proxy.get("port", None)
|
super().__init__(
|
||||||
))
|
socket.AF_INET6 if ipv6
|
||||||
|
else socket.AF_INET
|
||||||
|
)
|
||||||
|
|
||||||
|
self.settimeout(10)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user