官术网_书友最值得收藏!

Device auto detect

Netmiko provides a mechanism that can guess the device type and detect it. It uses a combination of SNMP discovery OIDS and executes several show commands on the remote console to detect the router operating system and type, based on the output string. Then netmiko will load the appropriate driver into the ConnectHandler() class:

#!/usr/local/bin/python
__author__ = "Bassim Aly"
__EMAIL__ = "basim.alyy@gmail.com"


from netmiko import SSHDetect, Netmiko

device = {
'device_type': 'autodetect',
'host': '10.10.88.110',
'username': 'admin',
'password': "access123",
}

detect_device = SSHDetect(**device)
device_type = detect_device.autodetect()
print(device_type)
print(detect_device.potential_matches)

device['device_type'] = device_type
connection = Netmiko(**device)

In the previous script:

  • The device_type inside the device dictionary will be autodetect, which will tell netmiko to wait and not load the driver till the netmiko guesses it.
  • Then we instruct the netmiko to perform device detection using the SSHDetect() class. The class will connect to the device using SSH and will execute some discovery commands to define the operating system type. The returned result will be a dictionary, and the best match will be assigned to the device_type variable using the autodetect() function.
  • You can see all the matching results by printing the potential_matches.
  • Now we can update the device dictionary and assign the new device_type to it.
主站蜘蛛池模板: 交城县| 隆德县| 峨山| 渭南市| 治县。| 繁峙县| 彝良县| 鄂伦春自治旗| 黑山县| 兴仁县| 抚州市| 平果县| 翁牛特旗| 潢川县| 阆中市| 伊吾县| 文昌市| 定结县| 扎囊县| 陕西省| 商洛市| 建平县| 虹口区| 开化县| 佳木斯市| 莲花县| 洛阳市| 莒南县| 调兵山市| 偃师市| 凤城市| 屯留县| 霍林郭勒市| 星座| 彝良县| 六安市| 五家渠市| 武宣县| 收藏| 广饶县| 页游|