from netmiko import ConnectHandler import time import re #pip3 install netmiko -->安装第三方库 hostip = [ '10.32.x.x',......... ] try: for i in hostip: H3C = { 'device_type':'hp_comware', 'host':i, 'username':'用户', 'password':'密码' } net_connect = ConnectHandler(**H3C) #验证是否执行成功 # net_connect.send_command('n') output = net_connect.send_command('display interface brief') # print(output) # print(type(output)) try : test = re.findall(r'GE.*\d.*?M.*\ [6|8]', output) with open("hostip-100M_v8", "a+") as f: for b in test: print(i + ":--->:" + b) f.write(i + ":--->:" + b + "\n") except Exception as e: print(i + "没有100M或者百兆端口") with open("hostip-100M_v8", "a+") as f: f.write(i + "没有100M或者10M端口" + "\n") except Exception as e: print(i + "不存在") with open("hostip-100M_v8", "a+") as f: f.write(i + "不存在或者登录不上"+ "\n") ############################################## # with open (i,"w") as f : # f.write(output) # time.sleep(0.02)
python-h3c交换机查看接口信息-刷选100M接口
最新推荐文章于 2024-05-23 17:47:03 发布