Files
SnarfCode/scripts/test_wan_pihole_sni.py

28 lines
1.0 KiB
Python

import socket
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
def test_external(domain, ip="174.106.252.96"):
print(f"\n=== Testing External Request to {domain} via {ip} ===")
with socket.create_connection((ip, 443), timeout=5) as sock:
with ctx.wrap_socket(sock, server_hostname=domain) as ssock:
req = f"GET /admin/ HTTP/1.1\r\nHost: {domain}\r\nUser-Agent: Mozilla/5.0\r\nConnection: close\r\n\r\n"
ssock.sendall(req.encode())
resp = b""
while True:
chunk = ssock.recv(4096)
if not chunk: break
resp += chunk
headers = resp.split(b"\r\n\r\n")[0].decode('utf-8', errors='ignore')
print("Headers:")
for line in headers.splitlines():
if any(k in line.lower() for k in ['http/1.1', 'location', 'set-cookie', 'server', 'content-length']):
print(" ", line)
test_external('pihole1.snarfnet.net')
test_external('pihole2.snarfnet.net')