From 8ea556b65fbc2440f81408ee52179ce1586e68ac Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 22 Sep 2018 14:44:12 +0200 Subject: [PATCH] Fix handling proxies with domain names --- pyrogram/connection/transport/tcp/tcp.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index ee29b960..2ee08d09 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -18,6 +18,7 @@ import logging import socket +import ipaddress try: import socks @@ -39,11 +40,14 @@ class TCP(socks.socksocket): port = proxy.get("port", None) try: - socket.inet_aton(hostname) - except socket.error: - super().__init__(socket.AF_INET6) - else: + ip_address = ipaddress.ip_address(hostname) + except ValueError: super().__init__(socket.AF_INET) + else: + if isinstance(ip_address, ipaddress.IPv6Address): + super().__init__(socket.AF_INET6) + else: + super().__init__(socket.AF_INET) self.set_proxy( proxy_type=socks.SOCKS5,