LczPtr 2020-04-10
#!/usr/bin/python3 #H3c交换机 import time from netmiko import ConnectHandler now = time.strftime("%Y%m%d",time.localtime(time.time())) log_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) ip_list = [ [‘sw-001‘,‘192.168.1.1‘], [‘sw-002‘,‘192.168.1.2‘], ] SW = { ‘device_type‘:‘hp_comware‘, ‘username‘:‘admin‘, ‘ip‘:‘‘, ‘password‘:"$password" } for ip_item in ip_list: SW[‘ip‘] = ip_item[1] connect = ConnectHandler(**SW) print(log_time + ‘Successfully connected to ‘ + ip_item[0]) output = connect.send_command(‘system view‘) iproute = connect.send_command("display ip routing-table") version = connect.send_command(‘dis version‘) fan = connect.send_command(‘display fan‘) cpu = connect.send_command(‘display cpu-usage‘) mem = connect.send_command(‘display memory‘) env = connect.send_command(‘display environment‘) fo = open(‘xusj‘,‘w‘) fo.write(iproute) fo.write(fan) fo.write(cpu) fo.write(mem) fo.write(env) fo.close()