ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.59k stars 1.31k forks source link

Timeout to SSH Confirmed and Reachable device #644

Closed LongBeachHXC closed 6 years ago

LongBeachHXC commented 6 years ago

Hey Kt,

I have the following code but the script is timing out when attempting to login to the devices. I have confirmed that I can SSH to the device and I can reach the device.

from getpass import getpass from netmiko import ConnectHandler from netmiko.ssh_exception import NetMikoTimeoutException from paramiko.ssh_exception import SSHException from netmiko.ssh_exception import AuthenticationException from ciscoconfparse import CiscoConfParse from napalm_base import get_network_driver import pandas as pd import re

test = pd.read_csv('cenc_final_task.csv', usecols=['IP Address','Interface'])

username = raw_input('Enter your SSH username: ') password = getpass()

for sample in test.iterrows():

sample = str(sample)

x = re.search(r'\S*Gi\S*',  sample)
y = re.search(r'\s\d+.\d+.\d+.\d+', sample)
if x:
    interface = x.group(0)
    if y:
        ip_address_of_device = y.group(0)

        ios_device = {
            'device_type': 'cisco_ios',
            'ip': ip_address_of_device,
            'username': username,
            'password': password,

}

        try:
            net_connect = ConnectHandler(**ios_device)
        except (AuthenticationException):
            print 'Authentication failure: ' + ip_address_of_device
            continue
        except (NetMikoTimeoutException):
            print 'Timeout to device: ' + ip_address_of_device
            continue
        except (EOFError):
            print "End of file while attempting device " + ip_address_of_device
            continue
        except (SSHException):
            print 'SSH Issue. Are you sure SSH is enabled? ' + ip_address_of_device
            continue
        except Exception as unknown_error:
            print 'Some other error: ' + str(unknown_error)
            continue

        config_data = net_connect.send_command_expect('show run')
        print (config_data)
        net_connect.disconnect()
LongBeachHXC commented 6 years ago

Okay nevermind...I see what is happening. I removed the exception handling and netmiko spit back

netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios 10.128.96.17:22

It appears that a colon and number are being added to the end of my IP addresses. So now I need to figure out how to remove the colon and number.

Thanks!