0

The following code fails to connect to a Cisco switch because of the:

RSA key fingerprint is 3e:b7:7b:55:6b:a3:xx:xx:xx:xx
Are you sure you want to continue connecting (yes/no)? yes

#!/usr/bin/env python

from __future__ import print_function
from netmiko import ConnectHandler
import sys
import time
import select
import paramiko
import re
fd = open(r'output_twinax.log','w') # Where you want the file to save to.
old_stdout = sys.stdout   
sys.stdout = fd 
platform = 'cisco_ios'
username = 'username' # edit to reflect
password = 'password' # edit to reflect

ip_add_file = open(r'IP-list','r') # a simple list of IP addresses you want to connect to each one o
n a new line

for host in ip_add_file:
    host = host.strip()
    device = ConnectHandler(device_type=platform, ip=host, username=username, password=password)
    find_hostname = device.find_prompt()
    hostname = find_hostname.replace(">","")
    print(hostname)
    output = device.send_command('terminal length 0')
    output = device.send_command('enable') #Editable to be what ever is needed
    output = device.send_command('sh int status | i SFP')
    print(output)
fd.close()

Please help modifying it to account for the RSA key. Thank you much.

theotherswan
  • 3
  • 1
  • 5
  • This question isn't really answerable without the stack trace on the failure. Accepting/rejecting the SSH host key is configurable in Netmiko (and will accept it by default)...so this really shouldn't be causing you a failure (hence the need to see the stack trace). – Kirk Byers Oct 19 '18 at 19:11

1 Answers1

0

Did you try use_keys keyword argument?

#!/usr/bin/env python

from __future__ import print_function
from netmiko import ConnectHandler
import sys
import time
import select
import paramiko
import re
fd = open(r'output_twinax.log','w') # Where you want the file to save to.
old_stdout = sys.stdout   
sys.stdout = fd 
platform = 'cisco_ios'
username = 'username' # edit to reflect
password = 'password' # edit to reflect

# List of IP addresses in each line
ip_add_file = open(r'IP-list','r') 
  key_file = "./rsa_key.txt"

for host in ip_add_file:
  host = host.strip()
  device = ConnectHandler(device_type=platform, 
                          ip=host, 
                          username=username,
                          key_file=key_file,
                          use_keys=True)
  find_hostname = device.find_prompt()
  hostname = find_hostname.replace(">","")
  print(hostname)
  output = device.send_command('terminal length 0')
  output = device.send_command('enable')
  output = device.send_command('sh int status | i SFP')
  print(output)
fd.close()
yoonghm
  • 4,198
  • 1
  • 32
  • 48