实验八 netmiko 模块

Netmiko 模块 4 种设备配置函数:
(1)send_command():向设备发送⼀条命令,通常⽤于查询、排错、保存等命令。
(2)send_config_set():向设备发送⼀条或多条配置命令,会⾃动适配到配置模式,通常配合指令列表。
(3)send_config_from_file():如 send_config_set() 指令列表过⼤,可单独放⼊⽂本中配合 send_config_from_file() 调⽤。
(4)send_command_timing():主动延迟等待,主要⽤于应对设备交互管理平台回显量⼤出现有意延迟或异常卡顿的现象。

在这里插入图片描述

netmiko 离线安装

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pNBbLaQZ-1654357907995)(../../图片/typora/1654332930028.png)]

from netmiko import ConnectHandler


sw1 = {'device_type':'huawei', 'ip':'192.168.1.9', 'username':'python', 'password':'123asd'}
commands = ['interface GigabitEthernet 0/0/1', 'description descby_send_config_set()']
with ConnectHandler(**sw1) as connect:
        print ("已经成功登陆交换机" + sw1['ip'])
# 公众号:释然IT杂谈
        print('===实验⽬的(1),交互形式推送⼀条指令。')
        output = connect.send_command('display interface description | include GE0/0/[12][^0-9]')
        print(output)
        print('===实验⽬的(2),列表形式推送多条指令。')
        output = connect.send_config_set(commands)
        print(output)
        print('===实验⽬的(3),⽂件形式推送多条指令。')
        output = connect.send_config_from_file('Demo08.txt')
        print(output)
        print('===最后再检查配置')
        output = connect.send_command('display interface description | include GE0/0/[12][^0-9]')
        print(output)
        # 华为设备的保存配置save后需要输⼊y进⾏确认,后⾯实验再演示。
Demo08.txt
interface GigabitEthernet 0/0/2
description descby_send_config_set()
C:\Users\82127\.conda\envs\pythonProject\python.exe E:/log/python/pythonProject/Demo08.py
已经成功登陆交换机192.168.1.9
===实验⽬的(1),交互形式推送⼀条指令。
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(e): ETHOAM down
(dl): DLDP down
(d): Dampening Suppressed
Interface                     PHY     Protocol Description            
GE0/0/1                       up      up       descby_send_config_set()
GE0/0/2                       down    down                            
===实验⽬的(2),列表形式推送多条指令。
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]description descby_send_config_set()
[Huawei-GigabitEthernet0/0/1]return
<Huawei>
===实验⽬的(3),⽂件形式推送多条指令。
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]interface GigabitEthernet 0/0/2
[Huawei-GigabitEthernet0/0/2]description descby_send_config_set()
[Huawei-GigabitEthernet0/0/2]return
<Huawei>
===最后再检查配置
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(e): ETHOAM down
(dl): DLDP down
(d): Dampening Suppressed
Interface                     PHY     Protocol Description            
GE0/0/1                       up      up       descby_send_config_set()
GE0/0/2                       down    down     descby_send_config_set()

进程已结束,退出代码0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

期待未来的男孩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值