# -*- coding: utf-8 -*- from __future__ import annotations import sys import tempfile from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") REMOTE_PY = r"""import json, urllib.request, time def list_tabs(): with urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=8) as resp: return json.loads(resp.read().decode()) def new_tab(url): req = urllib.request.Request( "http://127.0.0.1:9222/json/new", data=json.dumps({"url": url}).encode(), headers={"Content-Type": "application/json"}, ) with urllib.request.urlopen(req, timeout=8) as resp: return json.loads(resp.read().decode()) for url in ( "chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/dashboard.html", "chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/options.html", ): try: tab = new_tab(url) print("opened", url.split("/")[-1], "->", (tab.get("url") or "")[:120]) except Exception as exc: print("fail", url.split("/")[-1], exc) time.sleep(2) for tab in list_tabs(): u = tab.get("url") or "" if "dhdgffkkebhmkfjojejmpbldmpobfkfo" in u or "tampermonkey" in u: print("tab", u[:140]) """ 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) sftp = c.open_sftp() with sftp.file("/tmp/open_tm.py", "w") as f: f.write(REMOTE_PY) sftp.close() _i, o, e = c.exec_command("docker cp /tmp/open_tm.py douyinweb-neko-3:/tmp/open_tm.py && docker exec douyinweb-neko-3 python3 /tmp/open_tm.py", timeout=60) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace") if err.strip(): print("ERR", err[:1000]) c.close() if __name__ == "__main__": main()