# 使用SSH连接设备,使用STD执行多条命令
def ssh_exec_command2(device_ip, username, password, command1, command2):
port = 22
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(device_ip, port, username, password, timeout=10)
print('连接设备 ', device_ip)
channel = ssh_client.invoke_shell()
stdin = channel.makefile("wb")
channel.makefile()
stdout = channel.makefile("rb")
stdin.write(
f"""
{command1}
{command2}
quit
"""
)
print("执行完毕", device_ip)
output = stdout.read(999999)
print("读取完毕", device_ip)
ssh_client.close()
return output
我写的SSH连接网络设备读取配置的函数,在windows10操作系统下运行正常,但是在windows2012系统下,运行到 output = stdout.read(999999) 这一步的时候就卡住,需要等10分钟才会反应过来继续往下执行,请问一下是什么原因?