inspect_remote.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import paramiko
  2. def inspect_remote():
  3. host = "192.168.130.171"
  4. user = "roni"
  5. pw = "BTSai123"
  6. commands = {
  7. "Directory listing": "ls -la ~/LocalFoodAI",
  8. "Python processes": "ps aux | grep -i python",
  9. "Port binding (8000)": "ss -tln | grep 8000 || netstat -an | grep 8000 || true",
  10. "Recent logs (server.log)": "tail -n 20 ~/LocalFoodAI/server.log",
  11. "Network interfaces / IP info": "ip addr show | grep -E 'inet '",
  12. "UFW status": "sudo ufw status || true",
  13. "System uptime & load": "uptime"
  14. }
  15. try:
  16. print(f"Connecting to remote VM at {host}...")
  17. client = paramiko.SSHClient()
  18. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  19. client.connect(host, username=user, password=pw, timeout=10)
  20. print("Connected successfully. Running diagnostics...\n")
  21. for desc, cmd in commands.items():
  22. print("=" * 60)
  23. print(f"DIAGNOSTIC: {desc}")
  24. print(f"COMMAND: {cmd}")
  25. print("=" * 60)
  26. stdin, stdout, stderr = client.exec_command(cmd)
  27. out = stdout.read().decode().strip()
  28. err = stderr.read().decode().strip()
  29. if out:
  30. print(out)
  31. else:
  32. print("[No Output]")
  33. if err:
  34. print(f"\n[stderr]:\n{err}")
  35. print()
  36. client.close()
  37. except Exception as e:
  38. print(f"Error during inspection: {e}")
  39. if __name__ == "__main__":
  40. inspect_remote()