-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_resolve_relay_ipv4.py
More file actions
37 lines (28 loc) · 1.1 KB
/
06_resolve_relay_ipv4.py
File metadata and controls
37 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Resolve relay hostnames to current IPv4 addresses.
Use this when your client needs an IP literal instead of a domain — for
example, when the runtime resolver is unreliable, or when a load balancer
in front of your code can't do DNS lookups for upstream proxies.
WARNING: relay IPs change. Do not pin them in long-running config. Re-resolve
periodically (once per hour or on connection error) so you follow ProxyShard's
infrastructure changes.
"""
import socket
from proxyshard import RELAY_HOSTS
def resolve_all(host: str) -> list[str]:
"""Return every A record for `host`. Some relays are behind multiple IPs."""
try:
_, _, addrs = socket.gethostbyname_ex(host)
return addrs
except socket.gaierror as e:
raise RuntimeError(f"DNS lookup failed for {host}: {e}") from e
def main() -> None:
for region, host in RELAY_HOSTS.items():
try:
ips = resolve_all(host)
except RuntimeError as e:
print(f" {host} → ERROR: {e}")
continue
print(f" {host:30} → {', '.join(ips)}")
if __name__ == "__main__":
main()