0

我正在尝试使用 Napalm 使用 python chevron 中的 telnet 连接到 Cisco 路由器,并从 netmiko.ssh 收到错误。

这是我正在使用的片段

from napalm import get_network_driver

driver = get_network_driver('ios')

with driver('ip_address', 'username', 'password', optional_args={'port': 23,'transport': telnet}) as device:

    print(device.get_facts())

这是我收到的错误消息:

NAPALM didn't catch this exception. Please, fill a bugfix on https://github.com/napalm-automation/napalm/issues
Don't forget to include this traceback.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python39\lib\site-packages\napalm\base\base.py", line 46, in __enter__
    self.open()
  File "C:\Program Files\Python39\lib\site-packages\napalm\ios\ios.py", line 169, in open
    self.device = self._netmiko_open(
  File "C:\Program Files\Python39\lib\site-packages\napalm\base\base.py", line 86, in _netmiko_open
    self._netmiko_device = ConnectHandler(
  File "C:\Program Files\Python39\lib\site-packages\netmiko\ssh_dispatcher.py", line 312, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "C:\Program Files\Python39\lib\site-packages\netmiko\cisco\cisco_ios.py", line 17, in __init__
    return super().__init__(*args, **kwargs)
  File "C:\Program Files\Python39\lib\site-packages\netmiko\base_connection.py", line 346, in __init__
    self._open()
  File "C:\Program Files\Python39\lib\site-packages\netmiko\base_connection.py", line 351, in _open
    self.establish_connection()
  File "C:\Program Files\Python39\lib\site-packages\netmiko\base_connection.py", line 910, in establish_connection
    self.telnet_login()
  File "C:\Program Files\Python39\lib\site-packages\netmiko\cisco_base_connection.py", line 171, in telnet_login
    raise NetmikoAuthenticationException(msg)
netmiko.ssh_exception.NetmikoAuthenticationException: Login failed: ip_address
4

2 回答 2

0

为了能够与 Cisco-IOS/XE-Device 建立 SSH/Telnet-Session,您需要

a) 在“线路”级别启用用户身份验证:

line vty 0 15
 login local

b) 添加具有正确权限级别的本地用户帐户:

username testuser privilege 15 secret testpass

c) 为传入会话启用正确的协议:

line vty 0 15
 transport input telnet

telnet 可能是默认的,最好禁用它并切换到 ssh:

line vty 0 15
 transport input ssh 

完成此操作后,效果很好:

>>> with driver(hostname='192.168.193.139', username='testuser', password='testpass', optional_args={'port': 23,'transport': "telnet"}) as device:
...   print(device.get_facts())

...
{'uptime': 660, 'vendor': 'Cisco', 'os_version': 'Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.16.16, RELEASE SOFTWARE (fc2)', 'serial_number': '91STKVRFLW91', 'model': 'CSR1000V', 'hostname': 'CSR-VM', 'fqdn': 'CSR-VM.lab.local', 'interface_list': ['GigabitEthernet1', 'GigabitEthernet2', 'GigabitEthernet3', 'GigabitEthernet4', 'Loopback0', 'Loopback1000']}
于 2021-10-07T12:20:28.000 回答
0

在名为 ip_address 的主机上登录失败,如果 'ip_address' 是您尝试连接的主机的名称,也许您可​​以将主机 IP 放在适当的位置。

相信这个短视频可以帮助到你https://www.youtube.com/watch?v=QTapxlSEo1E

你会问自己把主机地址放在哪里吗?

您尝试连接的主机名称是“ip_address”吗?

对“用户名”和“密码”字段的相同问题。

你就在附近。最适合你的!

于 2021-01-06T04:01:35.267 回答