42 lines
No EOL
1.4 KiB
Python
42 lines
No EOL
1.4 KiB
Python
print("hi")
|
|
import httpx
|
|
import ssl
|
|
import certifi
|
|
|
|
def load_custom_dns_resolver():
|
|
"""Create a client with custom transports for Tor DNS bypass."""
|
|
|
|
def create_client_with_custom_dns(hostname_to_ip_map: dict):
|
|
"""
|
|
hostname_to_ip_map: {"example.com": "203.0.113.45", "other.com": "203.0.113.46"}
|
|
"""
|
|
mounts = {}
|
|
|
|
for hostname, ip in hostname_to_ip_map.items():
|
|
ctx = ssl.create_default_context(cafile=certifi.where())
|
|
ctx.check_hostname = True
|
|
ctx.verify_mode = ssl.CERT_REQUIRED
|
|
|
|
# transport = httpx.HTTPTransport(ssl_context=ctx, http2=True)
|
|
transport = httpx.HTTPTransport(ssl_context=context)
|
|
|
|
# Mount for both hostname and IP patterns
|
|
mounts[f"https://{hostname}"] = transport
|
|
mounts[f"https://{ip}"] = transport
|
|
|
|
# client = httpx.Client(mounts=mounts, http2=True)
|
|
client = httpx.Client(mounts=mounts)
|
|
return client
|
|
|
|
return create_client_with_custom_dns
|
|
|
|
# Usage
|
|
create_client = load_custom_dns_resolver()
|
|
client = create_client({"api.hydraveil.net": "185.165.169.91"})
|
|
|
|
# Connect to IP, but Host header and cert verification use original hostname
|
|
response = client.get("https://185.165.169.91/api/v1/cachedsync", headers={"Host": "api.hydraveil.net"})
|
|
|
|
|
|
print(response)
|
|
print(response.json) |