与Paramiko& amp;的Python SSH连接Netmiko libs

时间:2016-11-10 17:19:26

标签: python networking paramiko

如果有人可以提供帮助,我遇到了跳跃ssh连接问题。 我无法使用(Keith的Netmiko SSH代理支持),也许是因为我在windows box中运行。

所以我通过ssh连接到跃点服务器,然后使用paramiko lib连接到路由器。接下来我想拉netmiko来发送/检索命令/输出,但是当我用paramiko启动ssh连接时,我总是收到ConnectHandler的错误:

ERROR:
line 40, in <module>
    net_connect = ConnectHandler(device_type='cisco_ios', ip='x', username='x', password='x')
  File "build\bdist.win-amd64\egg\netmiko\ssh_dispatcher.py", line 96, in ConnectHandler
  File "build\bdist.win-amd64\egg\netmiko\base_connection.py", line 89, in __init__
  File "build\bdist.win-amd64\egg\netmiko\base_connection.py", line 396, in establish_connection
netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios x.x.x.x:22

在我的(简单)代码下面,我在编程方面非常新鲜,所以我的代码可能很糟糕:(。

import paramiko
import netmiko
from netmiko import ConnectHandler
from getpass import getpass
import time
import re
import sys

# First ssh connection
remote_conn_pre=paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
remote_conn_pre.connect(ip, port=22, username=username,  
                        password=password,
                        look_for_keys=False, allow_agent=False)

remote_conn = remote_conn_pre.invoke_shell()
output = remote_conn.recv(65535)
print output

# Second SSH connection
remote_conn.send("ssh x@ip x \n>")
time.sleep(3)
remote_conn.send("password\n")
output1 = remote_conn.recv(65535)
print output1
time.sleep(3)

# Trying to run netmiko...
net_connect = ConnectHandler(device_type='cisco_ios', ip='x.x.x.x', username='user', password='password') 
net_connect.find_prompt()

CISCO_SHOW_ACL_x = net_connect.send_command("show run | s access-list x ")

1 个答案:

答案 0 :(得分:0)

而不是category->get() =&gt;使用device_type='cisco_ios',它可能是语法的东西

相关问题