python使用netmiko连接交换机绑定mac
  6tuRdFP5lxfF 2023年11月02日 40 0

环境背景

python3.8,华为交换机 每次手动登录交换机再进行绑定操作,太过机械化啊,本着懒人原则,写一个脚本真不是事情

脚本

from netmiko import ConnectHandler
import time

def bing_mac(mac):
    sw_ip = '10.10.10.10'    #交换机ip
    username = 'admin'       #交换机账号
    password = 'xxxxxx'      #交换机密码
    type = 'huawei'	     #交换机类型,具体需要根据netmiko支持的类型去填
    device = ConnectHandler(device_type=type, ip=sw_ip, username=username, password=password)
    print('已连接上%s' % sw_ip)
    output= device.send_command('sys',expect_string = ']')
    print(output)
    time.sleep(1)
    cmd2= 'user-bind static mac-address %s  '%(mac)
    output=device.send_command(cmd2,expect_string = ']')
    print(output)
    time.sleep(2)
    print('已绑定:%s' % output)
    cmd4='quit'
    output = device.send_command(cmd4, expect_string='>')
    print(output)
    device.disconnect()


if __name__ == '__main__':
    print('正在绑定mac')
    mac = '088F-C3E3-F602'
    bing_mac(mac)
    print('mac已绑定成功')
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  9JCEeX0Eg8g4   2023年11月25日   37   0   0 ednpython
  38gcbVXUBcLA   2023年11月19日   27   0   0 python缩进
  6tuRdFP5lxfF   2023年11月22日   32   0   0 python日志记录
6tuRdFP5lxfF