May-16-2022, 11:54 AM
I wrote a code to go through an inventory list of Cisco devices and do some tasks. My problem is because the inventory list is huge, and no guarantee if the device is online or decommissioned, i have to run the code anyway and expect that connection error.
I noticed that when i connect to the device without proxy, it doesn't show this banner error for the offline device.
I'm using Netmiko, but here i'm stuck with this error when the device is offline:
Then the code when it comes to an offline device, it will give this error:
I noticed that when i connect to the device without proxy, it doesn't show this banner error for the offline device.
I'm using Netmiko, but here i'm stuck with this error when the device is offline:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
check1 = 0 try : #Avoid Timeout & Auth errors and continuo for next switch net_connect = ConnectHandler( * * switch) except (NetMikoTimeoutException, NetMikoAuthenticationException): print ( '\n' + 'Cannot connect to device: ' + HOST) check1 = 1 except paramiko.AuthenticationException: print ( '\n' + 'AuthenticationException ' + HOST) check1 = 1 except paramiko.SSHException as e: print ( '\n' + 'SSHException' + HOST) check1 = 1 except paramiko.ssh_exception.SSHException as e: if e.message = = 'Error reading SSH protocol banner' : print ( '\n' + 'SSHException' + HOST) check1 = 1 except paramiko.ssh_exception.NoValidConnectionsError as e: if e.message = = 'Error reading SSH protocol banner' : print ( '\n' + 'SSHException' + HOST) check1 = 1 if bool (check1) = = False : #If can connect, then continue... otherwise, skip to next host in the for loop |
Error: Exception (client): Error reading SSH protocol banner
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 2270, in _check_banner
buf = self.packetizer.readline(timeout)
File "/usr/local/lib/python3.6/site-packages/paramiko/packet.py", line 380, in readline
buf += self._read_timeout(timeout)
File "/usr/local/lib/python3.6/site-packages/paramiko/packet.py", line 622, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 2093, in run
self._check_banner()
File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 2275, in _check_banner
"Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Cannot connect to device: 10.25.44.4