# -*- coding: utf-8 -*- import paramiko SCRIPT = r''' import json, urllib.request, time raw = urllib.request.urlopen("http://127.0.0.1:8014/api/sessions?limit=5").read() d = json.loads(raw) for s in (d.get("sessions") or [])[:4]: cu = (s.get("cover_url") or "") cp = (s.get("cover_path") or "") print("ID", s.get("id")) print(" path", cp[:110]) print(" url ", cu[:110]) if cu.startswith("http"): try: req = urllib.request.Request(cu, method="HEAD") with urllib.request.urlopen(req, timeout=8) as r: print(" HEAD", r.status, r.headers.get("Content-Type"), r.headers.get("Content-Length")) except Exception as e: print(" HEAD_ERR", type(e).__name__, str(e)[:160]) t0 = time.time() try: with urllib.request.urlopen(cu, timeout=15) as r: body = r.read() print(" DIRECT", r.status, len(body), "%dms" % int((time.time() - t0) * 1000)) except Exception as e: print(" DIRECT_ERR", type(e).__name__, str(e)[:160]) t0 = time.time() try: with urllib.request.urlopen("http://127.0.0.1:8014/api/sessions/%s/cover" % s["id"], timeout=15) as r: body = r.read() print(" PROXY", r.status, len(body), "%dms" % int((time.time() - t0) * 1000)) except Exception as e: print(" PROXY_ERR", type(e).__name__, str(e)[:160]) print("---") ''' c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/probe_cover_speed.py", "w") as f: f.write(SCRIPT) sftp.close() stdin, stdout, stderr = c.exec_command("python3 /tmp/probe_cover_speed.py", timeout=90) print(stdout.read().decode("utf-8", "replace")) err = stderr.read().decode("utf-8", "replace") if err: print("ERR", err[-1000:]) c.close()