标签:prompt tomat aml exp git paramik quit 用户名 cno
此模块用于简化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 Linux Limited 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 VyOS Experimental 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
#前提准备模块: Paramiko >= 2.4.1 scp >= 0.10.0 pyyaml pyserial textfsm #安装netmiko pip install netmiko ps:没有全部安装前提模块,在使用netmiko没有报错,说明运行代码里没有调用到而已,而不是不需要
5.1 执行查看命令:show ip int brief
from netmiko import ConnectHandler cisco = { ‘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)
#执行命令,返回结果为字符串,赋值给output output = 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 ConnectHandler cisco = { ‘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)
1.https://pynet.twb-tech.com/blog/automation/netmiko.html
2.https://github.com/ktbyers/netmiko
标签:prompt tomat aml exp git paramik quit 用户名 cno
原文地址:https://www.cnblogs.com/lisenlin/p/10489494.html