**华为设备**

#!/usr/bin/python3

#华为交换机#糟老头子

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','10.0.1.1.1'],

]

SW = {

 'device_type':'huawei',

 'ip':'',

 'username':'admin',

 'password':"#########"

}

for ip_item in ip_list:

 SW['ip'] = ip_item[1]

 connect = ConnectHandler(**SW)

 print(log_time + '-----------------成功登录到交换机-----------------' + ip_item[1])

 output = connect.send_command('n')

 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')

 vlan = connect.send_command('display vlan')

 interface = connect.send_command('display  interface  brief')

 cu = connect.send_command('display  current-configuration')

 fo = open(ip_item[1]+'.txt','w',encoding='utf-8')

 fo.write(iproute)

 fo.write(fan)

 fo.write(cpu)

 fo.write(mem)

 fo.write(env)

 fo.write(vlan)

 fo.write(interface)

 fo.write(cu)

 fo.close()

 #糟老头子