Files

46 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""keycheck.py <bank.jsonl> [delay]
Проверка живости unr_sk_ ключей. Важно: probe с датацентр-IP бесполезен —
Cloudflare отдаёт 403 "error code: 1010" на любой запрос, а бурст ловит
429 "Too many requests from this IP address". Поэтому:
* User-Agent браузерный,
* шаг между запросами 1 с (настраивается),
* 429 = ключ, скорее всего, живой — нужно добить после паузы, а не считать мёртвым.
Выход: сводка + alive.txt со живыми ключами.
"""
import json
import sys
import time
import requests
BANK = sys.argv[1] if len(sys.argv) > 1 else "bank.jsonl"
DELAY = float(sys.argv[2]) if len(sys.argv) > 2 else 1.0
UA = {"User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/141.0 Safari/537.36"),
"Accept": "application/json"}
URL = "https://api.unrestricted.sh/v1/models"
rows = [json.loads(l) for l in open(BANK, encoding="utf-8", errors="replace") if l.strip()]
ok, codes = [], {}
for r in rows:
k = r.get("key") or ""
if not k.startswith("unr_sk_"):
continue
try:
s = requests.get(URL, headers={**UA, "Authorization": "Bearer " + k}, timeout=15)
st = s.status_code
except Exception as e:
st = type(e).__name__
codes[st] = codes.get(st, 0) + 1
if st == 200:
ok.append((k, float(r.get("balance") or 0)))
print(k[:14], st, flush=True)
time.sleep(DELAY)
print("проверено %d | живых %d | сумма $%.2f | коды %s"
% (len(rows), len(ok), sum(b for _, b in ok), codes))
with open("alive.txt", "w", encoding="utf-8") as f:
f.write("\n".join(k for k, _ in ok))