import paramiko import sys sys.stdout.reconfigure(encoding='utf-8') c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect('140.44.4.74', username='snarf', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10) def run(cmd): stdin, stdout, stderr = c.exec_command(cmd) return stdout.read().decode().strip(), stderr.read().decode().strip() print("--- nc test from 140.44.4.74 ---") out, err = run("nc -zv -w 2 14.4.4.44 3493") print("OUT:", out) print("ERR:", err) # Check NUT communication using python py_test = """ import socket s = socket.socket() s.settimeout(3) s.connect(('14.4.4.44', 3493)) s.sendall(b'VER\\n') print('VER response:', s.recv(1024)) s.sendall(b'LIST UPS\\n') print('LIST UPS response:', s.recv(1024)) s.close() """ out, err = run(f"python3 -c {repr(py_test)}") print("Python test out:\n", out) if err: print("Python test err:\n", err) c.close()