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())
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())
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容