1、基本信息
我公司之前采用的是人工巡檢,但奈何有大量網(wǎng)絡(luò)設(shè)備,往往巡檢需要花掉一上午(還是手速快的話),浪費時間浪費生命。
這段時間正好在學(xué) Python ,于是乎想(其)要(實)解(就)放(是)雙(懶)手。
好了,腳本很長又比較挫,有耐心就看看吧。
需要巡檢的設(shè)備如下:
設(shè)備清單 |
設(shè)備型號 |
防火墻 |
華為 E8000E |
H3C M9006 |
|
飛塔 FG3950B |
|
交換機 |
華為 S9306 |
H3C S12508 |
|
Cisco N7K |
|
路由器 |
華為 NE40E |
負載 |
Radware RD5412 |
Radware RD6420 |
2、采集數(shù)據(jù)并寫入文件
# 相關(guān)設(shè)備巡檢命令就不介紹了。。。
01DMZ-E8000E.py # 華為 E8000E 交互腳本
#!/usr/bin/env python import pexpect import sys import datetime d1=datetime.datetime.now() d3=d1+datetime.timedelta(days=-1) tdy=d3.strftime('%b %d') today=datetime.date.today().strftime('%Y%m%d') tt=tdy.split() if int(tt[-1]) < 10: tdy=tdy.replace('0',' ') ip=str(sys.argv[1]) passwd=str(sys.argv[2]) password=str(sys.argv[3]) child=pexpect.spawn('ssh 用戶名@%s'%ip) fout=file('/usr/sh/shell/linux/xunjian/'+today+'/01DMZ-E8000E.txt','w') child.logfile = fout child.expect('(?i)ssword:') child.sendline("%s"%passwd) child.expect('(?i)E8000E-1>') child.sendline("su") child.expect("(?i)assword:") child.sendline("%s"%password) child.expect("(?i)E8000E-1>") child.sendline("dis device | ex Normal") child.expect("(?i)E8000E-1>") child.sendline("dis version") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis temperature") child.expect("(?i)E8000E-1>") child.sendline("dir") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis memory-usage") child.expect("(?i)E8000E-1>") child.sendline("dis hrp state") child.expect("(?i)E8000E-1>") child.sendline("dis firewall session table") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis ip routing-table protocol static") child.expect("(?i)E8000E-1>") child.sendline("dis int brief | in up") child.expect("(?i)E8000E-1>") child.sendline("dis acl 3004") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis acl 3005") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis acl 3006") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis acl 3007") index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send("a") child.expect("(?i)E8000E-1>") child.sendline("dis alarm all") child.expect("(?i)E8000E-1>") child.sendline("dis logbuffer | in %s"%tdy) for i in range(20): index = child.expect(["(?i)---- More ----","(?i)E8000E-1>"]) if ( index == 0 ): child.send(" ") else: child.sendline("q") break
文章名稱:對Python網(wǎng)絡(luò)設(shè)備巡檢腳本的實例講解-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://aaarwkj.com/article6/doppog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、面包屑導(dǎo)航、做網(wǎng)站、品牌網(wǎng)站制作、搜索引擎優(yōu)化、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)