54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
import json, os, random, re, sys, time
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
import requests
|
|
|
|
UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36"}
|
|
SOURCES = [
|
|
"https://api.proxyscrape.com/v4/free-proxy-list/get?request=display_proxies&protocol=http&proxy_format=ipport&format=text&timeout=5000",
|
|
"https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt",
|
|
"https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/http.txt",
|
|
"https://raw.githubusercontent.com/proxifly/free-proxy-list/main/proxies/protocols/http/data.txt",
|
|
"https://raw.githubusercontent.com/clarketm/proxy-list/master/proxy-list-raw.txt",
|
|
]
|
|
TARGET = "https://www.context.dev/"
|
|
OUT = "proxies_live.json"
|
|
|
|
def grab():
|
|
out = set()
|
|
for u in SOURCES:
|
|
try:
|
|
r = requests.get(u, timeout=30, headers=UA)
|
|
for line in r.text.splitlines():
|
|
line = line.strip()
|
|
m = re.search(r"(\d{1,3}(?:\.\d{1,3}){3}):(\d{2,5})", line)
|
|
if m:
|
|
out.add("%s:%s" % (m.group(1), m.group(2)))
|
|
print(u.split("/")[2], len(out), flush=True)
|
|
except Exception as e:
|
|
print("src err", u.split("/")[2], type(e).__name__, flush=True)
|
|
return list(out)
|
|
|
|
def test(px):
|
|
p = {"http": "http://" + px, "https": "http://" + px}
|
|
try:
|
|
r = requests.get(TARGET, proxies=p, timeout=12, headers=UA, allow_redirects=False)
|
|
return px, r.status_code
|
|
except Exception:
|
|
return px, 0
|
|
|
|
pool = grab()
|
|
print("total proxies", len(pool), flush=True)
|
|
random.shuffle(pool)
|
|
pool = pool[:1200]
|
|
good = []
|
|
with ThreadPoolExecutor(max_workers=100) as ex:
|
|
futs = [ex.submit(test, px) for px in pool]
|
|
for i, f in enumerate(as_completed(futs), 1):
|
|
px, st = f.result()
|
|
if st == 200:
|
|
good.append(px)
|
|
print("OK", px, flush=True)
|
|
if i % 200 == 0:
|
|
print("checked", i, "good", len(good), flush=True)
|
|
json.dump(good, open(OUT, "w"), indent=1)
|
|
print("GOOD", len(good), flush=True) |