#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Проверка БОЕВЫХ Reality-входов (2087/2053) снаружи, по-честному.""" import json import subprocess import time VPS = "193.233.210.184" XRAY = "/usr/local/bin/xray" def sh(cmd, timeout=60): return subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout) r = sh("ssh -o BatchMode=yes root@%s cat /root/.buryan-reality" % VPS) info = dict(l.split("=", 1) for l in r.stdout.strip().splitlines() if "=" in l) print("=== ДАННЫЕ БОЕВОГО REALITY ===") for k in ("PUBLIC_KEY", "SHORT_ID", "SERVER_NAME", "PORT", "DEST"): v = info.get(k, "") print(" %-12s %s" % (k, (v[:20] + "...") if k == "PUBLIC_KEY" else v)) keys = json.load(open("/root/buryan-infra/ops/vpn/build/keys.json", encoding="utf-8")) socks = 10910 print() print("=== ПРОВЕРЯЮ БОЕВЫЕ ПОРТЫ КЛЮЧОМ akadmin ===") uid = keys["akadmin"] for port in (2087, 2053): socks += 1 client = { "log": {"loglevel": "warning"}, "inbounds": [{"listen": "127.0.0.1", "port": socks, "protocol": "socks", "settings": {"udp": True, "auth": "noauth"}}], "outbounds": [{"protocol": "vless", "settings": {"vnext": [{"address": VPS, "port": port, "users": [{"id": uid, "encryption": "none"}]}]}, "streamSettings": { "network": "tcp", "security": "reality", "realitySettings": { "serverName": info["SERVER_NAME"], "fingerprint": "firefox", "publicKey": info["PUBLIC_KEY"], "shortId": info["SHORT_ID"], "spiderX": "/"}}}], } p = "/tmp/live-%d.json" % port json.dump(client, open(p, "w", encoding="utf-8"), ensure_ascii=False, indent=2) proc = subprocess.Popen([XRAY, "run", "-config", p], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) time.sleep(5) ip = sh("curl -s --max-time 15 --socks5-hostname 127.0.0.1:%d " "https://api.ipify.org" % socks).stdout.strip() proc.terminate() try: proc.wait(timeout=5) except Exception: proc.kill() print(" порт %-5s %s" % (port, "РАБОТАЕТ" if ip == VPS else "нет (%s)" % (ip or "—"))) print() print("=== ЧТО СКАЗАЛ СЕРВЕР ПРО БОЕВЫЕ ВХОДЫ ===") r = sh("ssh -o BatchMode=yes root@%s \"journalctl -u xray --since '3 min " "ago' --no-pager | grep -iE 'reality|invalid|rejected|accepted' | " "tail -10\"" % VPS) for line in r.stdout.strip().splitlines(): print(" " + line[-140:])