#!/usr/bin/env python3 """Collect live HTTP(S) proxies for browser waves: fetch public lists, probe via https.""" import concurrent.futures as cf import json import os import re import subprocess import sys OUT = os.environ.get("PX_OUT", "C:/Users/User/tmp/numes/proxies_http.txt") LIMIT = int(os.environ.get("PX_LIMIT", "600")) SOURCES = [ "https://api.proxyscrape.com/v4/free-proxy-list/get?request=display_proxies&protocol=http&proxy_format=ipport&format=text&timeout=8000", "https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/http.txt", "https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt", "https://raw.githubusercontent.com/proxifly/free-proxy-list/main/proxies/protocols/http/data.txt", ] def fetch(url): try: r = subprocess.run(["curl", "-sL", "-m", "40", url], capture_output=True, text=True, timeout=60, errors="replace") return r.stdout or "" except Exception: return "" def parse(txt): out = set() for m in re.finditer(r"(\d{1,3}(?:\.\d{1,3}){3}):(\d{2,5})", txt): out.add("%s:%s" % (m.group(1), m.group(2))) return out def probe(hp, timeout=12): url = "https://api.ipify.org" try: r = subprocess.run(["curl", "-s", "-m", str(timeout), "-x", "http://" + hp, url], capture_output=True, text=True, timeout=timeout + 6) ip = (r.stdout or "").strip() if ip and len(ip) < 20 and ip.count(".") == 3: return hp, ip except Exception: pass return hp, "" def main(): cands = set() for u in SOURCES: t = fetch(u) got = parse(t) print("%-70s %d" % (u.split("/")[2], len(got))) cands |= got # свой relay на прод-хосте тоже годится как egress cands = list(cands)[:LIMIT * 4] print("candidates:", len(cands)) live = [] with cf.ThreadPoolExecutor(max_workers=120) as ex: for hp, ip in ex.map(probe, cands): if ip: live.append((hp, ip)) # dedupe by egress ip: один egress = одна полоса seen, uniq = set(), [] for hp, ip in live: if ip in seen: continue seen.add(ip) uniq.append(hp) with open(OUT, "w", encoding="utf-8") as f: for hp in uniq: f.write(hp + "\n") print("live:", len(live), "unique egress:", len(uniq), "->", OUT) if __name__ == "__main__": main()