netmiko: Netmiko SSH Timeout

I am having issues SSH to a Cisco IOS device. I have tested manual SSH directly from box that I am running the script from with NO issues.

Thanks for any assistance.

#!/usr/bin/env python

from netmiko import ConnectHandler

with open('commands_file') as f:
    commands_list = f.read().splitlines()

with open('devices_file') as f:
    devices_list = f.read().splitlines()

for devices in devices_list:
    print 'Connecting to device" ' + devices
    ip_address_of_device = devices_list
    ios_device = {
        'device_type': 'cisco_ios',
        'ip': 'ip_address_of_device',
        'username': '',
        'password': '',
        'secret': ''
    }

    net_connect = ConnectHandler(**ios_device)
    output = net_connect.send_config_set(commands_list)
    print output

    net_connect = ConnectHandler(**ios_device)
    output = net_connect.send_command_expect('test aaa group tacacs+ readonly Temp1234 legacy')
    print output

Connecting to device" 10.128.96.37
Traceback (most recent call last):
  File "westfieldisescript.py", line 23, in <module>
    net_connect = ConnectHandler(**ios_device)
  File "/usr/local/lib/python2.7/dist-packages/netmiko/ssh_dispatcher.py", line 131, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 150, in __init__
    self.establish_connection()
  File "/usr/local/lib/python2.7/dist-packages/netmiko/base_connection.py", line 506, in establish_connection
    raise NetMikoTimeoutException(msg)
netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios ip_address_of_device:22

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (7 by maintainers)

Most upvoted comments

I don’t think the way you are creating your array of devices works the way you intend…

import time
devices = '''
          192.168.1.100
          192.168.1.86
          192.168.17.1
          '''.strip().splitlines()

print(devices)
for device in devices:
        print('~'*79)
        print('Connection to Device -',device,'-')
        time.sleep(1)

results in output that looks like the following…

['192.168.1.100', '          192.168.1.86', '          192.168.17.1']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection to Device - 192.168.1.100 -
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection to Device -           192.168.1.86 -
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection to Device -           192.168.17.1 -

notice the leading spaces on all but the first “host”, that is why you are getting the underlying socket.gaierror: [Errno 11001] getaddrinfo failed error, and subsequent netmiko.ssh_exception.NetMikoTimeoutException: Connection to device