paramiko

import paramiko
ssh=paramiko.SSHClient()
know_host=paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(know_host)
ssh.connect(
    hostname="10.10.21.82",
    port=22,
    username="root",
    password="123"
)
shell=ssh.invoke_shell()
shell.settimeout(1)
command=input(">>>")+"\n"
shell.sent(command)
while True:
    try:
        recv=shell.recv(51.2).decode()
        if recv:
            print(recv)
        else:
            continue
    except:
        command=input(">>>")+"\n"
        shell.sent(command)
ssh.close()

 

posted @ 2019-06-28 22:42  爱学习的小猫咪  阅读(176)  评论(0编辑  收藏  举报