# -*- coding: utf-8 -*- from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") CMD = r""" docker exec douyinweb-neko-3 python3 - <<'PY' import json, urllib.request junk = ("tampermonkey.net/changelog", "tampermonkey.net/installed") with urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=5) as resp: tabs = json.loads(resp.read().decode()) for tab in tabs: url = tab.get("url") or "" if any(x in url for x in junk): tid = tab.get("id") if tid: urllib.request.urlopen(f"http://127.0.0.1:9222/json/close/{tid}", timeout=3) print("closed", url[:90]) with urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=5) as resp: tabs = json.loads(resp.read().decode()) print("tabs_after", len(tabs)) PY """ def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=60, allow_agent=False, look_for_keys=False) _i, o, e = c.exec_command(CMD, timeout=60) print(o.read().decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()