1. 程式人生 > >ssh 執行命令並實時顯示結果

ssh 執行命令並實時顯示結果

usr port set import exit div code baidu while

ssh 執行命令並實時顯示結果

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()

ssh 執行命令並實時顯示結果