- Hands-On Enterprise Automation with Python.
- Bassem Aly
- 209字
- 2021-06-18 19:22:34
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.
推薦閱讀
- 機器人Python青少年編程開發(fā)實例
- Python數(shù)據(jù)分析(第2版)
- Mastering Swift 2
- Python應用輕松入門
- 零基礎(chǔ)學Java程序設計
- Python漫游數(shù)學王國:高等數(shù)學、線性代數(shù)、數(shù)理統(tǒng)計及運籌學
- Java 11 Cookbook
- KnockoutJS Starter
- Unreal Engine 4 Shaders and Effects Cookbook
- Mastering Android Development with Kotlin
- SQL Server與JSP動態(tài)網(wǎng)站開發(fā)
- 利用Python進行數(shù)據(jù)分析
- JavaScript應用開發(fā)實踐指南
- 網(wǎng)絡數(shù)據(jù)采集技術(shù):Java網(wǎng)絡爬蟲實戰(zhàn)
- Java面試一戰(zhàn)到底(基礎(chǔ)卷)