首页 > 其他 > 详细

ssh 执行命令并实时显示结果

时间:2019-04-18 00:52:45      阅读:367      评论:0      收藏:0      [点我收藏+]

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 执行命令并实时显示结果

原文:https://www.cnblogs.com/diysoul/p/10727107.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!