# -*- coding: utf-8 -*- """Diagnose ShellCrash proxies and find a working egress node.""" from __future__ import annotations import json import sys import urllib.parse import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") GUEST_PW = "4669805" def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 4014, "eric", GUEST_PW, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False, ) script = r''' set -e echo '=== core ===' systemctl is-active shellcrash curl -sS -m 3 http://127.0.0.1:9999/version echo echo '=== cfg firewall ===' grep -E '^(firewall_area|mix_port|redir_mod|dns_mod)=' /etc/ShellCrash/configs/ShellCrash.cfg || true echo '=== delay test top nodes ===' # url-test a few candidates python3 <<'PY' import json, urllib.request, urllib.parse, ssl ctx = ssl.create_default_context() base = "http://127.0.0.1:9999" nodes = [ "socks5", "proxycheap", "242af835-singbox_hysteria", "hackrobot-singbox_tuic", "VLESS_Reality_Vision", "242af835-singbox_hysteria2", "1d2da142-singbox_hysteria5", "1d2da142-singbox_tuic5", "e3ea3b30-singbox_hysteria_vultr", "e3ea3b30-singbox_tuic_vultr", ] # get available with urllib.request.urlopen(base + "/proxies", timeout=5) as r: proxies = json.load(r).get("proxies") or {} print("available", [n for n in nodes if n in proxies]) for n in nodes: if n not in proxies: continue enc = urllib.parse.quote(n, safe="") url = f"{base}/proxies/{enc}/delay?timeout=5000&url=http://www.gstatic.com/generate_204" try: with urllib.request.urlopen(url, timeout=8) as r: d = json.load(r) print(f"delay {n}: {d}") except Exception as e: print(f"delay {n}: FAIL {e}") PY echo '=== pick best and set SELECT + GLOBAL ===' python3 <<'PY' import json, urllib.request, urllib.parse base = "http://127.0.0.1:9999" nodes = [ "socks5", "242af835-singbox_hysteria", "hackrobot-singbox_tuic", "VLESS_Reality_Vision", "1d2da142-singbox_tuic5", "1d2da142-singbox_hysteria5", "e3ea3b30-singbox_hysteria_vultr", "e3ea3b30-singbox_tuic_vultr", ] with urllib.request.urlopen(base + "/proxies", timeout=5) as r: proxies = json.load(r).get("proxies") or {} best = None best_delay = 10**9 for n in nodes: if n not in proxies: continue enc = urllib.parse.quote(n, safe="") url = f"{base}/proxies/{enc}/delay?timeout=5000&url=http://www.gstatic.com/generate_204" try: with urllib.request.urlopen(url, timeout=8) as r: d = json.load(r) delay = int(d.get("delay") or 0) if delay > 0 and delay < best_delay: best, best_delay = n, delay except Exception: pass print("best", best, best_delay) if not best: raise SystemExit(0) # set groups for group in ["GLOBAL", "πŸš€ θŠ‚η‚Ήι€‰ζ‹©", "🌐 ιžδΈ­ε›½", "🐟 漏网之鱼"]: if group not in proxies and group != "GLOBAL": continue enc = urllib.parse.quote(group, safe="") req = urllib.request.Request( f"{base}/proxies/{enc}", data=json.dumps({"name": best}).encode(), headers={"Content-Type": "application/json"}, method="PUT", ) try: with urllib.request.urlopen(req, timeout=5) as r: print("set", group, "->", best, r.status) except Exception as e: print("set", group, "FAIL", e) PY echo '=== egress ===' env -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u all_proxy \ curl -sS -m 10 -o /dev/null -w 'direct_baidu:%{http_code}\n' https://www.baidu.com || echo direct_baidu:fail env -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u all_proxy \ curl -sS -m 12 -o /dev/null -w 'mixed_google:%{http_code}\n' -x http://127.0.0.1:7890 https://www.google.com/generate_204 || echo mixed_google:fail env -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u all_proxy \ curl -sS -m 12 -o /dev/null -w 'mixed_cf:%{http_code}\n' -x http://127.0.0.1:7890 https://1.1.1.1 || echo mixed_cf:fail ''' sftp = c.open_sftp() with sftp.file("/tmp/_sc_fix_egress.sh", "w") as f: f.write(script.replace("\r\n", "\n")) sftp.close() _, o, e = c.exec_command( f"echo '{GUEST_PW}' | sudo -S -p '' bash /tmp/_sc_fix_egress.sh", timeout=180, ) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())