import requests, urllib3, sys, json
urllib3.disable_warnings()
BASE = "https://www.fansky.net"
paths = [l.strip() for l in open('endpoints.txt') if l.strip()]
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
    'Accept': 'application/json, text/plain, */*',
}
s = requests.Session()
s.headers.update(headers)
s.verify = False
out = []
for p in paths:
    url = BASE + p
    try:
        r = s.get(url, timeout=20, allow_redirects=False)
        body = r.text[:300].replace('\n',' ').replace('\r',' ')
        out.append((r.status_code, len(r.content), p, body))
    except Exception as e:
        out.append(('ERR', 0, p, str(e)[:120]))
# print summary of interesting (non-401/404) responses
print("=== NON 401/404 responses ===")
for code, size, p, body in out:
    if code not in (401, 404):
        print(f"{code}\t{size}\t{p}\t{body[:200]}")
print()
print("=== counts ===")
from collections import Counter
c = Counter(str(x[0]) for x in out)
print(dict(c))
# save full
with open('sweep_get.json','w') as f:
    json.dump([{'code':x[0],'size':x[1],'path':x[2],'body':x[3]} for x in out], f, indent=1)
