netmiko使用案例8 自动检测设备类型或者协议

autodetect_ssh.py

#!/usr/bin/env python
from netmiko import SSHDetect, Netmiko
from getpass import getpass

device = {
    'device_type': 'autodetect',
    'host': '10.0.1.7', 
    '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())
netmiko使用案例8 自动检测设备类型或者协议_第1张图片
image.png

autodetect_snmp.py

from netmiko.snmp_autodetect import SNMPDetect
from netmiko import Netmiko
from getpass import getpass

device = {
    'host': 'cisco1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
}

snmp_community = getpass("Enter SNMP community: ")
my_snmp = SNMPDetect("cisco1.twb-tech.com", snmp_version="v2c", community=snmp_community)
device_type = my_snmp.autodetect()
print(device_type)

device['device_type'] = device_type
net_connect = Netmiko(**device)
print(net_connect.find_prompt())

autodetect_snmp_v3.py

# SNMPv3
from netmiko.snmp_autodetect import SNMPDetect
from netmiko import Netmiko
from getpass import getpass

device = {
    'host': 'cisco1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
}

snmp_key = getpass("Enter SNMP community: ")
my_snmp = SNMPDetect("cisco1.twb-tech.com", snmp_version="v3", user='pysnmp',
                     auth_key=snmp_key, encrypt_key=snmp_key, auth_proto="sha",
                     encrypt_proto="aes128")
device_type = my_snmp.autodetect()
print(device_type)

device['device_type'] = device_type
net_connect = Netmiko(**device)
print(net_connect.find_prompt())

你可能感兴趣的:(netmiko使用案例8 自动检测设备类型或者协议)