#!/usr/bin/env python3 """Single SSH attempt + flush everything immediately. No long silent waits.""" from __future__ import annotations import socket import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True) HOST = "107.173.30.245" def tcp(port, timeout=3.0): s = socket.socket() s.settimeout(timeout) try: s.connect((HOST, port)) print(f"TCP {port}=OPEN", flush=True) return True except Exception as ex: print(f"TCP {port}=CLOSED ({type(ex).__name__}: {ex})", flush=True) return False finally: try: s.close() except Exception: pass print("=== port scan ===", flush=True) for p in (22, 80, 443, 4014, 7000, 8014, 51820): tcp(p) print("=== ssh once ===", flush=True) t0 = time.time() try: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( HOST, 22, "root", "Xiao4669805", timeout=15, banner_timeout=20, auth_timeout=20, allow_agent=False, look_for_keys=False, ) print(f"SSH OK in {time.time()-t0:.1f}s", flush=True) cmd = ( "echo HI; uptime; free -h | head -2; " "systemctl is-active caddy douyinweb-api douyinweb-web docker frpp 2>/dev/null; " "ss -lntp 2>/dev/null | grep -E ':(443|80|8014|4015|4014)\\b' || true" ) _i, o, e = c.exec_command(cmd, timeout=40) # stream-ish while not o.channel.exit_status_ready(): if o.channel.recv_ready(): sys.stdout.write(o.channel.recv(4096).decode("utf-8", "replace")) sys.stdout.flush() time.sleep(0.2) sys.stdout.write(o.read().decode("utf-8", "replace")) sys.stdout.write(e.read().decode("utf-8", "replace")) sys.stdout.flush() c.close() except Exception as ex: print(f"SSH FAIL in {time.time()-t0:.1f}s: {type(ex).__name__}: {ex}", flush=True) raise SystemExit(1) print("DONE_ONCE", flush=True)