代码基于python Netmiko包(已默认华三设备)
变量 | |
---|
dev_ip | 设备IP |
username | ssh账号 |
password | ssh密码 |
source_vlan | 源VLAN |
change_vlan | 改变的VLAN |
| |
def info(dev_ip,username,password,
source_vlan ,
change_vlan):
ssh = ConnectHandler(host=dev_ip, username=username, password=password, device_type='hp_comware', port=22)
rec_info = ssh.send_command('dis int brief | inc '+
source_vlan )
int_rule = re.compile(r'GE[0-9]/0/[0-9]{1,2}')
port = re.findall(int_rule, rec_info)
create_dir = str(datetime.date.today())
txt = ''
for i in port:
txt += 'int ' + i + '\n'
txt += 'port acc vl '+
change_vlan +'\n'
txt += 'save f'
with open(create_dir + '//' + str(dev_ip) + '刷入脚本.txt', 'w') as f:
f.write(txt)
return txt
def create_task():
create_dir = str(datetime.date.today())
if not os.path.exists(create_dir):
os.mkdir(create_dir)
tasks = []
for ip in ip_list:
info(ip)
ip_list = []#输入需要修改的设备ip
create_task()
可以按照这个文章的来 https://zhuanlan.zhihu.com/p/458428159