0

以下代码无法连接到 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 密钥。非常感谢。

4

1 回答 1

0

您是否尝试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()
于 2018-10-01T08:29:04.677 回答