NETMIKO Notes
NETMIKO Notes
Netmiko is a Python-based SSH client. Now, rather than connecting to each device separately from a GUI client and
issuing the desired commands one by one, the whole process can be automated with Python, and the commands can
be applied to all devices at once if necessary. Netmiko is actually a wrapper for Paramiko (the de facto SSH library in
Python) with some added network intelligence for sending commands, logging in to devices, and so on, which is why
Netmiko is becoming the de facto SSH client for networking devices.
Netmiko supports more than 20 vendors, most notably Cisco, with Cisco IOS, Cisco IOS XE, and Cisco Nexus Operating
System (NX-OS).
Netmiko has many functions (methods) that developers can use while interacting with the device. Because it is a very
long list, the most useful ones are discussed here with a detailed description and applicable use cases.
• ConnectHandler(): This Python class initiates a connection with the device. You will need to provide an IP
address, username, password, and device type information to successfully initiate a connection.
Example:
• is_alive(): This method determines if the connection with the device is alive and returns True or False.
Example:
>>> device.is_alive()
True
>>> device.is_alive()
True
>>> device.disconnect()
>>> device.is_alive()
False
% cat interface_conf.cfg
interface GigabitEthernet1
description SALES
>>> device.send_config_file( "/home/student/config_files/interface_conf.cfg")
'config term\nEnter configuration commands, one per line. End with CNTL/Z.\ncsr1kv1(config)#interface
GigabitEthernet1\ncsr1kv1(config-if)# description SALES\ncsr1kv1(config-if)#end\ncsr1kv1#'
>>> print(interface_config)
['interface GigabitEthernet1', 'description HR']
>>> device. send_config_set(interface_config)
'config term\nEnter configuration commands, one per line. End with CNTL/Z.\ncsr1 kv1(config)#interface
GigabitEthernet1\ncsr1kv1(config-if)#description HR\ncsr1kv1(config-if)#end\ncsr1kv1#'
• session_timeout: This variable defines the number of seconds after which the session should time out. It can
be defined with ConnectHandler as an extra argument or can be changed after the connection is initiated.
The default value is 60 seconds.
Example: