使用telnet连接到Cisco IOS路由器的Napalm



我正试图使用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 FilesPython39libsite-packagesnapalmbasebase.py", line 46, in __enter__
self.open()
File "C:Program FilesPython39libsite-packagesnapalmiosios.py", line 169, in open
self.device = self._netmiko_open(
File "C:Program FilesPython39libsite-packagesnapalmbasebase.py", line 86, in _netmiko_open
self._netmiko_device = ConnectHandler(
File "C:Program FilesPython39libsite-packagesnetmikossh_dispatcher.py", line 312, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "C:Program FilesPython39libsite-packagesnetmikociscocisco_ios.py", line 17, in __init__
return super().__init__(*args, **kwargs)
File "C:Program FilesPython39libsite-packagesnetmikobase_connection.py", line 346, in __init__
self._open()
File "C:Program FilesPython39libsite-packagesnetmikobase_connection.py", line 351, in _open
self.establish_connection()
File "C:Program FilesPython39libsite-packagesnetmikobase_connection.py", line 910, in establish_connection
self.telnet_login()
File "C:Program FilesPython39libsite-packagesnetmikocisco_base_connection.py", line 171, in telnet_login
raise NetmikoAuthenticationException(msg)
netmiko.ssh_exception.NetmikoAuthenticationException: Login failed: ip_address

在名为ip_address的主机上登录失败,如果"ip_address"是您尝试连接的主机的名称,也许您可以将主机ip设置到位。

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

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

您尝试连接的主机的名称是"ip_address"?

"用户名"one_answers"密码"字段也有同样的问题。

你就在附近。给你最好的!

要能够建立到需要的Cisco IOS/XE设备的SSH/Telnet会话

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']}

我想你忘了把telnet这个词放在引号或撇号之间。下面的片段在我的睾丸中起作用。只需进行以下更改:

dev_creds = {
'hostname': '172.16.0.3',
'username': 'cisco',
'password': 'cisco',
'optional_args': {'secret': 'cisco', "port": 23, 'transport': 'telnet'}
}
device = driver(**dev_creds)

相关内容

  • 没有找到相关文章

最新更新