Модификация кода Python 3 для работы с отпечатком ключа RSA

Следующий код не может подключиться к коммутатору Cisco из-за:

Отпечаток ключа RSA: 3e:b7:7b:55:6b:a3:xx:xx:xx:xx
Вы уверены, что хотите продолжить подключение (да / нет)? да

#!/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()

Пожалуйста, помогите изменить его для учета ключа RSA. Спасибо много.

1 ответ

Ты пробовал use_keys ключевой аргумент?

#!/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()
Другие вопросы по тегам