最近因工作需要,上面要求,每天需上报运维的几百数通设备端口使用情况【】,虽然有现成网管监控工具监控设备状态,但做报表,有点不方便,特写了个小脚本。
注:测试运行于ubuntn,需安装snmpwalk工具,
目标数通设备,需做好相关snmp配置
复制代码 代码如下:
#/usr/bin/python
#coding:utf-8
import os,sys
import re
from pprint import pprint
#甯歌鍘傚鏁伴?氳澶嘙IB鍊?
MIB = {
'public':{
'ports':{
'string':'.1.3.6.1.2.1.2.2.1.2',
'status':'.1.3.6.1.2.1.2.2.1.8', #2 down
}
},
'huawei':{
},
'cisco':{
}
}
#绔彛鐘舵?佽浆鎹?
def portStatus(_s):
if int(_s)==2:
return 'down'
elif int(_s)==1:
return 'up'
else:
return 'none'
#鎵ц绯荤粺鍛戒护snmpwalk璋冪敤
def snmpwalk(host,publicKey,iso):
return [i.strip() for i in os.popen('/usr/bin/snmpwalk -c %s -v 2c %s %s'%(publicKey,host,iso)).readlines()]
def getPorts(_ip,_public,option):
if option == 'ports':
postsString = (j.split('=')[1].split(':')[1].replace('"','').strip() for j in snmpwalk(_ip,_public,MIB['public']['ports']['string']))
postsStatus = (int(j.split('=')[1].split(':')[1].strip()) for j in snmpwalk(_ip,_public,MIB['public']['ports']['status']))
return zip(postsString,postsStatus)
else:
print('on this commmnad')
publicKey = 'hi' #sunmp public key
HOSTS={
'10.221.98.2':{'type':'switch','origin':'quidway','public':publicKey},
'10.221.98.3':{'type':'switch','origin':'quidway','public':publicKey},
'10.221.97.108':{'type':'firewall','origin':'h3c','public':publicKey},
'10.231.98.233':{'type':'switch','origin':'cisco','public':publicKey},
}
if __name__ == '__main__':
for i in HOSTS.keys():
for host,status in getPorts(i,HOSTS[i]['public'],'ports'):
print("%s\t%s\t%s"%(i,host.ljust(30),portStatus(status).ljust(20)))
print(''.ljust(50,'#'))
运行结果
复制代码 代码如下:
root@ubuntn12:/tmp# python snmpwalk.py
10.221.98.2 InLoopBack0 up
10.221.98.2 NULL0 up
10.221.98.2 GigabitEthernet0/0/0 down
10.221.98.2 Aux0/0/1 down
10.221.98.2 Vlanif100 up
10.221.98.2 Eth-Trunk1 down
10.221.98.2 Eth-Trunk1.32 down
10.221.98.2 Eth-Trunk1.50 down
10.221.98.2 Eth-Trunk1.60 down
10.221.98.2 Eth-Trunk1.70 down
10.221.98.2 Eth-Trunk1.80 down
10.221.98.2 Eth-Trunk1.100 down
10.221.98.2 Eth-Trunk1.110 down
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 《原神》「星路拾忆」网页活动壁纸展示
- 群星.2024-祝你幸福!电影原声带【阿里巴巴】【FLAC分轨】
- 于台烟.2004-执着【乾坤唱片】【WAV+CUE】
- 黄品源.2004-感谢·情人(引进版)【滚石】【WAV+CUE】
- 《最终幻想16》评测:游、戏两难全的系列转折
- 《纸嫁衣》五部打包¥104,《鬼泣5》仅需¥44
- 《崩坏:星穹铁道》造物大赛卷出新高度
- 《王菲 菲常传奇 2CD》[WAV+CUE][950MB]
- 《王菲 空灵独味唱腔 非常传奇 紫水晶2CD》[WAV+CUE][860MB]
- 《车载专业测试王1号 极品音质》[WAV/分轨][980MB]
- 炉石传说的国服回归送什么奖励 炉石传说9.25回归最新消息介绍
- 云顶之弈最强阵容汇总2024 云顶之弈最强阵容搭配最新版本
- S14lol全球总决赛在哪观看 lol全球总决赛观赛直播地址汇总
- 黄思婷2011-感谢天[豪记唱片][WAV+CUE]
- 孙淑媚2013-太阳[台湾首版][WAV+CUE]