一、简介
此模块用于简化paramiko与网络设备之间的ssh连接,可在windows与Unix平台使用
二、目前支持的设备
(2019.03.07)
Regularly tested Arista vEOS Cisco ASA Cisco IOS Cisco IOS-XE Cisco IOS-XR Cisco NX-OS Cisco SG300 HP Comware7 HP ProCurve Juniper Junos LinuxLimited testing Alcatel AOS6/AOS8 Apresia Systems AEOS Calix B6 Cisco AireOS (Wireless LAN Controllers) Dell OS9 (Force10) Dell OS10 Dell PowerConnect Extreme ERS (Avaya) Extreme VSP (Avaya) Extreme VDX (Brocade) Extreme MLX/NetIron (Brocade/Foundry) Huawei IP Infusion OcNOS Mellanox NetApp cDOT OneAccess Palo Alto PAN-OS Pluribus Ruckus ICX/FastIron Ubiquiti EdgeSwitch Vyatta VyOSExperimental A10 Accedian Aruba Ciena SAOS Citrix Netscaler Cisco Telepresence Check Point GAiA Coriant Dell OS6 Dell EMC Isilon Eltex Enterasys Extreme EXOS Extreme Wing Extreme SLX (Brocade) F5 TMSH F5 Linux Fortinet MRV Communications OptiSwitch Nokia/Alcatel SR-OS QuantaMesh Rad ETX
三、实验环境
1.操作系统:win10
2.python版本: python3.6.6
3.netmiko模块版本:2.3.0
四、安装netmiko模块
#前提准备模块(安装netmiko可自动下载依赖项):Paramiko >= 2.4.1scp >= 0.10.0pyyamlpyserialtextfsm#安装netmikopip install netmiko
ps:没有全部安装前提模块,在使用netmiko没有报错,说明运行代码里没有调用到而已,而不是不需要
五、简单实例
5.1 执行查看命令:show ip int brief
from netmiko import ConnectHandlercisco = { 'device_type':'cisco_ios', 'host':'ip地址', 'username':'用户名', 'password':'密码'}net_connect = ConnectHandler(**cisco)##或者# net_connect = ConnectHandler(device_type='cisco_ios',host='IP地址',username='用户名',password='密码')#找到目前所在视图current_view = net_connect.find_prompt()print(current_view)#执行命令,返回结果为字符串,赋值给outputoutput = net_connect.send_command('show ip int brief')print(output)# #此为在windows里如果/n不能显示回车,则进行如下语句格式化# o_list = output.split("/n")# for line in o_list:# print(line)
5.2 执行配置命令:手动关闭接口G1/0/29
from netmiko import ConnectHandlercisco = { 'device_type':'cisco_ios', 'host':'ip地址', 'username':'用户名', 'password':'密码'}net_connect = ConnectHandler(**cisco)##或者# net_connect = ConnectHandler(device_type='cisco_ios',host='IP地址',username='用户名',password='密码')#要配置的命令config_commands = ['interface GigabitEthernet1/0/29','shutdown']#提交要配置的命令,input为提交的真实内容input = net_connect.send_config_set(config_commands)#验证shutdown是否执行成功output = net_connect.send_command('show run inter gi1/0/29')print(output)# #此为在windows里如果/n不能显示回车,则进行如下语句格式化# o_list = output.split("/n")# for line in o_list:# print(line)
新闻热点
疑难解答