72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Inventory running services on dylive VPS (107.173.30.245)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "107.173.30.245"
|
|
PASS = "Xiao4669805"
|
|
|
|
|
|
def connect():
|
|
last = None
|
|
for i in range(12):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
HOST,
|
|
22,
|
|
"root",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=180,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
print(f"connected attempt={i}", flush=True)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print(f"retry {i} {type(ex).__name__}: {ex}", flush=True)
|
|
time.sleep(8)
|
|
raise SystemExit(f"ssh failed: {last}")
|
|
|
|
|
|
def run(c, cmd, timeout=120):
|
|
print(f"\n===== {cmd[:100]} =====", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-12000:] if len(out) > 12000 else out, flush=True)
|
|
return out
|
|
|
|
|
|
def main():
|
|
c = connect()
|
|
try:
|
|
run(c, "uptime; free -h | head -3; df -h / | tail -1")
|
|
run(c, "systemctl list-units --type=service --state=running --no-pager --no-legend")
|
|
run(c, "docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' 2>/dev/null | head -60")
|
|
run(c, "ss -lntup | head -80")
|
|
run(
|
|
c,
|
|
"systemctl list-unit-files --type=service --state=enabled --no-pager --no-legend | "
|
|
"awk '{print $1}' | grep -Eiv '^(ssh|sshd|systemd|dbus|cron|rsyslog|network|NetworkManager|"
|
|
"ufw|fail2ban|docker|containerd|caddy|nginx|douyinweb|getty|user@|snap|multipath|"
|
|
"irqbalance|polkit|ModemManager|packagekit|unattended|chrony|ntp|qemu|serial)' | head -80",
|
|
)
|
|
run(c, "systemctl list-units --type=service --state=running --no-pager --no-legend | awk '{print $1}'")
|
|
run(c, "ls /etc/systemd/system/douyinweb* 2>/dev/null; ls /etc/caddy 2>/dev/null; which caddy nginx 2>/dev/null")
|
|
run(c, "ps aux --sort=-%mem | head -25")
|
|
finally:
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|