import paramiko def main(): sshClient = paramiko.SSHClient() sshClient.set_missing_host_key_policy(paramiko.AutoAddPolicy()) sshClient.connect(hostname = "192.168.1.104", port = 22, username = "usr", password = "pwd") shell = sshClient.invoke_shell() shell.sendall("ping www.baidu.com -c 3\n") shell.sendall("exit\n") while True: data = shell.recv(2048).decode() if not data: print("quit now") break print(data, end = "") sshClient.close() if __name__ == ‘__main__‘: main()
原文地址:https://www.cnblogs.com/diysoul/p/10727107.html
时间: 2024-11-09 07:09:31