国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

Python自動巡檢H3C交換機(jī)實現(xiàn)過程解析

瀏覽:4日期:2022-07-14 09:40:47

1.通過netmiko模塊登錄交換機(jī),協(xié)議ssh,執(zhí)行收集信息命令,保存至txt文件

2.過濾txt文件中的內(nèi)容,保存到excel,使用xlwt模塊實現(xiàn)。

3.sendmai發(fā)送excel郵件。或者發(fā)送給釘釘機(jī)器人也可以

4.使用crond定時發(fā)送巡檢報表。

代碼如下

#!/usr/bin/python3 #H3c交換機(jī)import timefrom netmiko import ConnectHandlernow = 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()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 丰原市| 牟定县| 通河县| 恩施市| 建湖县| 清徐县| 夏邑县| 色达县| 威信县| 乌审旗| 葵青区| 肇东市| 射洪县| 繁昌县| 遵义县| 晋城| 微山县| 炎陵县| 汉沽区| 元江| 怀柔区| 色达县| 平安县| 和政县| 周宁县| 平泉县| 山东省| 武乡县| 荃湾区| 濮阳县| 华容县| 喜德县| 沾益县| 靖州| 凉城县| 繁峙县| 南投市| 道真| 呼伦贝尔市| 宝坻区| 龙海市|