大家好,您已经看到了,所有链接都使这个主题变得生动,我做不到。
有人可以告诉我在使用paramiko执行命令后如何打印输出吗?
SSH连接正常 我与开关连接 但是无法获得输出
import paramiko
import sys
ipAddress = "192.168.10.10"
username = "cisco"
password = "Cisco12345"
def getNeighbours(ip, user, passw):
while True:
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=user, password=passw, look_for_keys=False, allow_agent=False)
break
except paramiko.AuthenticationException:
sys.exit(1)
# Use invoke_shell to establish an 'interactive session'
remote_conn = ssh.invoke_shell()
remote_conn.send("cisco")
remote_conn.send("\n")
remote_conn.send("Cisco12345")
remote_conn.send("\n")
stdin, stdout, stderr = ssh.exec_command('show ap auto-rf 802.11b AP0038.DF1A.65A8')
print(stdout.read())
print("Command done, closing SSH connection")
ssh.close()
getNeighbours(ipAddress, username, password)
错误
文件“ neighbours.py”,第32行,在 getNeighbours(ipAddress,用户名,密码)在getNeighbours中的文件“ neighbours.py”第25行
stdin, stdout, stderr = ssh.exec_command('show ap auto-rf 802.11b AP0038.DF1A.65A8') File
“ / home / jfonseca / .local / lib / python3.6 / site-packages / paramiko / client.py”, 第499行,在exec_command中
chan.exec_command(command) File "/home/jfonseca/.local/lib/python3.6/site-packages/paramiko/channel.py",
第72行,在_check中
return func(self, *args, **kwds) File "/home/jfonseca/.local/lib/python3.6/site-packages/paramiko/channel.py",
第257行,在exec_command中
self._wait_for_event() File "/home/jfonseca/.local/lib/python3.6/site-packages/paramiko/channel.py",
第1208行,在_wait_for_event
raise e paramiko.ssh_exception.SSHException: Channel closed.