75 lines
2.8 KiB
Python
75 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Verify TUIC guard + selection on phys + VPS."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import http.cookiejar
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def ssh(label, host, port, user, pw, sudo=False):
|
|
print(f"\n===== {label} =====")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False)
|
|
|
|
def run(cmd, t=60):
|
|
if sudo:
|
|
cmd = f"echo '{pw}' | sudo -S -p '' bash -lc {repr(cmd)}"
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
print(run(
|
|
"systemctl is-active douyinweb-shellcrash-tuic-guard.service douyinweb-api.service; "
|
|
"systemctl is-active shellcrash.service 2>/dev/null; "
|
|
"systemctl --no-pager -l status douyinweb-shellcrash-tuic-guard.service 2>/dev/null | sed -n '1,18p'"
|
|
))
|
|
print(run(
|
|
"curl -sS -m 5 http://127.0.0.1:9999/proxies | python3 -c "
|
|
"\"import sys,json; d=json.load(sys.stdin); ps=d.get('proxies') or {}; "
|
|
"print('now', (ps.get('🚀 节点选择') or {}).get('now') or (ps.get('GLOBAL') or {}).get('now')); "
|
|
"print('tuic_delay', end=' ');\" 2>/dev/null; "
|
|
"curl -sS -m 8 'http://127.0.0.1:9999/proxies/1d2da142-singbox_tuic5/delay?timeout=5000&url=http://www.gstatic.com/generate_204' || echo delay_fail"
|
|
))
|
|
print(run(
|
|
"systemctl show douyinweb-api -p Environment --no-pager | tr ' ' '\\n' | grep SHELLCRASH || true"
|
|
))
|
|
c.close()
|
|
|
|
|
|
def pub(base):
|
|
cj = http.cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
req = urllib.request.Request(
|
|
base + "/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"}
|
|
)
|
|
op.open(req, timeout=30)
|
|
with op.open(urllib.request.Request(base + "/api/network/shellcrash/status"), timeout=40) as r:
|
|
d = json.loads(r.read().decode())
|
|
sc = d.get("shellcrash") or d
|
|
print(
|
|
base,
|
|
"running=", sc.get("running"),
|
|
"selected=", sc.get("selected_node"),
|
|
"family=", sc.get("selected_family"),
|
|
"default=", sc.get("default_node"),
|
|
"allow_vless=", sc.get("allow_vless_autopick"),
|
|
"unit=", sc.get("unit"),
|
|
)
|
|
|
|
|
|
ssh("phys", "107.173.30.245", 4014, "eric", "4669805", sudo=True)
|
|
ssh("vps", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
|
|
print("\n===== public =====")
|
|
for b in ("https://dy.nomadro.com", "https://dylive.nomadro.com"):
|
|
try:
|
|
pub(b)
|
|
except Exception as e:
|
|
print(b, e)
|