python脚本批量修改华为交换机端口配置
2015-09-02 15:53
761 查看
用python写的,主要是telnetlib库的应用,华为交换机批量修改端口配置,把已经UP的端口做一个port sec的mac sticky绑定,DOWN的端口,就clear配置信息。
使用前,先在交换机上 dis int bri,查出交换机的端口状态信息并复制到此脚本同目录下,以 IP.txt这样的格式命名的文件(比如 192.168.0.1对应 192.168.0.1.txt),以下内容记得把IP跟账号密码改成自己的。
使用前,先在交换机上 dis int bri,查出交换机的端口状态信息并复制到此脚本同目录下,以 IP.txt这样的格式命名的文件(比如 192.168.0.1对应 192.168.0.1.txt),以下内容记得把IP跟账号密码改成自己的。
import sys,os,telnetlib,re ip = '你的IP' txtfile = ip + '.txt' tel = telnetlib.Telnet(ip) tel.read_until('Username:') tel.write('你的账号'+'\n') tel.read_until('Password:') tel.write('你的密码'+'\n') tel.read_until('>') tel.write('sys'+'\n') file1 = open(txtfile) while True: a = file1.readline() if a == '':break int1 = a[:21] if re.search('up',a): print int1,' up' tel.read_until(']') tel.write('int'+' '+ int1 +'\n') tel.read_until(']') tel.write('port-security enable'+'\n') tel.read_until(']') tel.write('port-security mac-address sticky'+'\n') else: print int1,' down' tel.read_until(']') tel.write('int'+' '+ int1 +'\n') tel.read_until(']') tel.write('clear configuration this '+'\n') tel.read_until('[Y/N] :') tel.write('Y' + '\n') tel.read_until(']') tel.write('undo shutdown'+'\n') tel.close()
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法