我想建立SSH会话,运行第一个命令块,然后运行第二个命令块,但我只需要从第二个块捕获输出。 我怎样才能以更干净和正确的方式清理paramiko中的recv buffer? 现在我重新建立了SSH会话,但在我看来,它既丑陋又愚蠢
client=paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('10.10.10.50', username='admin', password='admin')
x=client.invoke_shell()
x.send('en')
x.send('\n')
x.send('conf t')
x.send('\n')
x.send('hostname 11')
x.send('\n')
x.send('exit')
x.send('\n')
x.close()
time.sleep(1)
client.connect('10.10.10.50', username='admin', password='admin')
x=client.invoke_shell()
x.send('sh users\n')
time.sleep(1)
output=x.recv(65535)
print output
提前谢谢!在
您可以尝试下面的代码清除“x.send('sh users\n')”之前的缓冲区
在评论中解决:
相关问题 更多 >
编程相关推荐