Update app.py
Browse files
app.py
CHANGED
|
@@ -31,11 +31,13 @@ try:
|
|
| 31 |
_original_getaddrinfo = socket.getaddrinfo
|
| 32 |
|
| 33 |
def patched_getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
try:
|
| 36 |
res = dns.resolver.Resolver()
|
| 37 |
res.nameservers = ['8.8.8.8', '1.1.1.1']
|
| 38 |
-
answers = res.resolve(
|
| 39 |
ip_address = answers[0].to_text()
|
| 40 |
return [(socket.AF_INET, type, proto, '', (ip_address, port))]
|
| 41 |
except Exception:
|
|
|
|
| 31 |
_original_getaddrinfo = socket.getaddrinfo
|
| 32 |
|
| 33 |
def patched_getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
|
| 34 |
+
# Convert host to string if it is bytes to avoid TypeError
|
| 35 |
+
host_str = host.decode() if isinstance(host, bytes) else host
|
| 36 |
+
if host_str and any(domain in host_str for domain in BYPASS_DOMAINS):
|
| 37 |
try:
|
| 38 |
res = dns.resolver.Resolver()
|
| 39 |
res.nameservers = ['8.8.8.8', '1.1.1.1']
|
| 40 |
+
answers = res.resolve(host_str, 'A')
|
| 41 |
ip_address = answers[0].to_text()
|
| 42 |
return [(socket.AF_INET, type, proto, '', (ip_address, port))]
|
| 43 |
except Exception:
|