Netmiko automatically detects the type of network device and executes the command

What is netmiko

netmiko is a Python library that helps you log in and operate network devices with SSH. It currently supports Cisco IOS, Juniper JunOS, Palo Alto PAN-OS, and more. Login, config mode transition, logout, etc. are abstracted as methods, and individual commands are a type of library that directly specifies commands. It is less abstract than NAPALM in this respect. It can be installed with pip intall netmiko etc.

--GitHub repository - ktbyers/netmiko: Multi-vendor library to simplify Paramiko SSH connections to network devices

Automatic detection function

In netmiko, it is usually necessary to set a parameter called device_type when creating a connection object, and in Cisco IOS it was specified as" cisco_ios ".

device_When explicitly specifying type


remote_device = {'device_type': 'cisco_ios',
                 'host': '192.168.0.254',
                 'username': 'user',
                 'password': 'passwordpassword'}

The recently released version 1.3.0 adds a feature called "SSH autodetect" that automatically detects device_type.

As far as I read auto_detect.py, the models that can be automatically detected are limited to the models originally supported by netmiko. It seems that there is, but this time I tried to check if it can detect Cisco IOS for the time being. (Almost the same as the example in the comment in the above source)

Code example

Automatic detection


from netmiko.ssh_autodetect import SSHDetect
from netmiko.ssh_dispatcher import ConnectHandler

#Parameter setting device_type is set to autodetect here
remote_device = {'device_type': 'autodetect',
                 'host': '192.168.0.254',
                 'username': 'user',
                 'password': 'passwordpassword'}

#Automatic detection
guesser = SSHDetect(**remote_device)
best_match = guesser.autodetect()

#Debug output of detection results
print("device_type: " + best_match)

#Automatically detected device_Reset type
remote_device['device_type'] = best_match
connection = ConnectHandler(**remote_device)

#Output of command execution result
print(connection.send_command('show version'))

#Disconnect
connection.disconnect()

Output example

Output example



device_type: cisco_ios ← Detected device_type

Cisco IOS Software, C181X Software (C181X-ADVENTERPRISEK9-M), Version 15.1(4)M4, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2012 by Cisco Systems, Inc.
Compiled Tue 20-Mar-12 23:34 by prod_rel_team

  ~Abbreviation~

-------------------------------------------------
Device#	  PID			SN
-------------------------------------------------
*0  	  CISCO1812-J/K9        ***********     
Configuration register is 0x2102

The auto-detection worked fine and I was able to see the show version results as well.

reference

--netmiko general tutorial - https://pynet.twb-tech.com/blog/automation/netmiko.html

Recommended Posts

Netmiko automatically detects the type of network device and executes the command
Automatically determine and process the encoding of the text file
Check the type and version of your Linux distribution
Bitwise operations including the return type and cast of numpy.random.choice
[EC2] How to install chrome and the contents of each command
A command to easily check the speed of the network on the console
About the basic type of Go
Touch the object of the neural network
I tried to control the network bandwidth and delay with the tc command