Napalm connection to Cisco IOS router using telnet

1.3k Views Asked by At

I'm trying to use Napalm to connect to Cisco routers using telnet from the python chevron and getting an error from netmiko.ssh.

Here is the snippet that I am using

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())

Here is the error message that I am receiving:

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
3

There are 3 best solutions below

0
On

to be able to establish an SSH/Telnet-Session to an Cisco-IOS/XE-Device you need to

a) enable user-authentication at the "line"-level:

line vty 0 15
 login local

b) add a local user account with correct privilege level:

username testuser privilege 15 secret testpass

c) enable the correct protocol for incoming sessions:

line vty 0 15
 transport input telnet

telnet might be default, good idea to disable this and switch to ssh:

line vty 0 15
 transport input ssh 

having done this, this works just fine:

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

Login failed on the host with name ip_address, if 'ip_address' is the name of the host you trying to connect, maybe you can to put the host IP in place.

I believe that this short video can help you https://www.youtube.com/watch?v=QTapxlSEo1E

Do you ask yourself where to put the host address?

The name of the host you are trying to connect is 'ip_address'?

The same question to the fields 'username' and 'password'.

You are near. The best for you!

0
On

I think you forgot to put the word telnet between quotation marks or apostrophes. The snippet below worked in my testes. Just make the following changes:

dev_creds = {
    'hostname': '172.16.0.3',
    'username': 'cisco',
    'password': 'cisco',
    'optional_args': {'secret': 'cisco', "port": 23, 'transport': 'telnet'}
}

device = driver(**dev_creds)