Skip to content

Commit 8ea556b

Browse files
committed
Fix handling proxies with domain names
1 parent 28abcaa commit 8ea556b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • pyrogram/connection/transport/tcp

pyrogram/connection/transport/tcp/tcp.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import logging
2020
import socket
21+
import ipaddress
2122

2223
try:
2324
import socks
@@ -39,11 +40,14 @@ def __init__(self, ipv6: bool, proxy: dict):
3940
port = proxy.get("port", None)
4041

4142
try:
42-
socket.inet_aton(hostname)
43-
except socket.error:
44-
super().__init__(socket.AF_INET6)
45-
else:
43+
ip_address = ipaddress.ip_address(hostname)
44+
except ValueError:
4645
super().__init__(socket.AF_INET)
46+
else:
47+
if isinstance(ip_address, ipaddress.IPv6Address):
48+
super().__init__(socket.AF_INET6)
49+
else:
50+
super().__init__(socket.AF_INET)
4751

4852
self.set_proxy(
4953
proxy_type=socks.SOCKS5,

0 commit comments

Comments
 (0)