Code is the same which is posted in the use_cases.
from netmiko import SSHDetect, Netmiko
from getpass import getpass
device = {
"device_type": "autodetect",
"host": "10.55.128.70",
"username": "admin",
"password": getpass(),
}
guesser = SSHDetect(**device)
best_match = guesser.autodetect()
print(best_match) # Name of the best device_type to use further
print(guesser.potential_matches) # Dictionary of the whole matching result
device["device_type"] = best_match
connection = Netmiko(**device)
print(connection.find_prompt())
Output --
As you could see below, script was able to detect the platform correctly but then couldn't stay connected. Is this an expected behaviour? Am trying to run a list of commands once the device is detected. But am seeing authentication failed message..
rashenba-mac:~ rajaraman$ python autodetect.py
Password:
cisco_nxos
{u'cisco_nxos': 99}
Traceback (most recent call last):
File "autodetect.py", line 18, in
connection = Netmiko(*device)
File "/Library/Python/2.7/site-packages/netmiko/ssh_dispatcher.py", line 218, in ConnectHandler
return ConnectionClass(args, **kwargs)
File "/Library/Python/2.7/site-packages/netmiko/base_connection.py", line 270, in __init__
self.establish_connection()
File "/Library/Python/2.7/site-packages/netmiko/base_connection.py", line 793, in establish_connection
raise NetMikoAuthenticationException(msg)
netmiko.ssh_exception.NetMikoAuthenticationException: Authentication failure: unable to connect cisco_nxos 10.55.128.70:22
Authentication failed.
From the output it appears that your auth fails. Maybe hardcode your password in there to give that a shot. Code from your post works as expected for me.
@carlniger Thank you for the reply. we use 2 FA for password. Will see if i can use a service account.
@carlniger @ktbyers Is there a way to make this work with user giving the password? Was able to test on a juniper device with hardcoded password.
@rajaramanlala I think that entirely depends on your 2fa and how that works, so I dont think I can help with that. You could look at something like this issue for some guidance though.
Try to print your passcode on screen, since you are calling a function to get the password... Likely it is where it breaks, if hardcode login fine
@carlniger that's exactly what i was looking for, maybe need to work more on my googling skills :) Thanks much for that reference.
@paulcfyiu Right, that's exactly where it breaks, with hardcoded credentials it works fine. .
@rajaramanlala keep us posted on how the 2fa goes, would love to see what you end up with!
Most helpful comment
@rajaramanlala I think that entirely depends on your 2fa and how that works, so I dont think I can help with that. You could look at something like this issue for some guidance though.