spark-server/deploy/geo-guard/probe_proxy_geo.py
DESKTOP-L8OUL9F\gfl0034 94dd2d819c Add mainland China geo gate (allow Shanghai/overseas).
Nginx auth_request plus MaxMind City lookup blocks non-Shanghai mainland CN with a fixed notice page for sparkmessenger/sparkmsg (and deploy helpers for the shared Singapore host).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-22 15:28:04 +08:00

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
import socket
import ssl
def http_via_proxy(sni, client_ip, path="/"):
raw = socket.create_connection(("127.0.0.1", 8443), timeout=8)
hdr = f"PROXY TCP4 {client_ip} 127.0.0.1 54321 8443\r\n".encode()
raw.sendall(hdr)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
tls = ctx.wrap_socket(raw, server_hostname=sni)
req = (
f"GET {path} HTTP/1.1\r\n"
f"Host: {sni}\r\n"
f"Connection: close\r\n\r\n"
).encode()
tls.sendall(req)
data = b""
while True:
chunk = tls.recv(4096)
if not chunk:
break
data += chunk
tls.close()
head = data.split(b"\r\n\r\n", 1)[0].decode("latin1", "replace")
status = head.split("\r\n", 1)[0]
body = data.split(b"\r\n\r\n", 1)[1] if b"\r\n\r\n" in data else b""
snippet = body[:160].decode("utf-8", "replace").replace("\n", " ")
print(f"{sni} ip={client_ip} -> {status} | {snippet!r}")
if __name__ == "__main__":
for sni in ("sparkmsg.wyrs365.com", "www.fullstorynovel.com"):
http_via_proxy(sni, "114.80.80.80") # Shanghai
http_via_proxy(sni, "223.5.5.5") # Hangzhou
http_via_proxy(sni, "8.8.8.8") # US