【发布时间】:2020-08-11 02:07:23
【问题描述】:
我正在尝试通过 paramiko 配置 cisco 路由器。
首先我 ssh 到路由器,然后运行命令。但是当我连接到路由器时,我无法进入配置模式。
我的意思是路由器以用户模式连接并运行en 或conf t 不起作用!
conn = paramiko.SSHClient()
conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn.connect("20.0.0.1", 22, "cisco", "123")
stdin, stdout, stderr = conn.exec_command('show ip int br')
status = stdout.channel.exit_status_ready()
if status==0:
mystring = stdout.read()
print mystring
状态为0,但mystring为空字符串。(结果为:[])
我在 Fedora 20 上。
谢谢
【问题讨论】:
-
stderr怎么样?en的 stdout 和 stderr 呢? -
其实我是 python 新手。我通过搜索找到了这个代码。对不起,我不明白你的问题!
-
连接后尝试:
print conn.get_transport().is_active()所以:连接成功了吗? -
感谢您的回复。运行
print conn.get_transport().is_active()的结果是true。 -
我发现 exec_command 是一个非阻塞调用。所以我编辑了我的代码,但我没有任何结果!