linux snmp octectstring 记录
参考
【Python】SNMP的安装及Python的调用
https://blog.youkuaiyun.com/yannanxiu/article/details/55045108
snmpwalk -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587
snmpget -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587.1800
snmpget -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587.1765
snmpget -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587.1827
snmpget -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587.1765
snmpget -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587.1827
snmpget -v 2c -c public 192.168.99.32 1.3.6.1.4.1.77587.1827
snmpget -v 2c -c public 192.168.99.32 1.3.6.1.4.1.77587.1827
SNMPv2-SMI::enterprises.77587.1827 = Hex-STRING: 7B 22 66 69 65 6C 64 5F 6E 61 6D 65 22 3A 20 22
73 61 74 5F 69 6E 66 6F 32 30 22 2C 20 22 76 61
6C 75 65 22 3A 20 22 31 30 30 2E 35 30 E5 BA A6
2C 20 31 32 37 34 39 2E 37 35 30 4D 48 7A 2C 20
E5 9E 82 E7 9B B4 E6 9E 81 E5 8C 96 22 2C 20 22
74 69 6D 65 73 74 61 6D 70 22 3A 20 31 36 34 39
39 30 30 33 34 37 2E 31 36 36 39 35 37 39 7D
snmpget -v 2c -c public 192.168.99.31 1.3.6.1.4.1.77587.1765
['SNMPv2-SMI::enterprises.77587.1765 = STRING: "{\\"field_name\\": \\"current_roll\\", \\"value\\": \\"+14.33\\", \\"timestamp\\": 1649903282.4113624}"']
python解析处理snmp回显----snmp
https://blog.youkuaiyun.com/weixin_30457881/article/details/97905674
# coding=utf-8
import re
import os,sys
import time
import platform
if 'Windows' == platform.system():
hosts = ['127.0.0.1']
else:
# 在虚拟机运行时则查看本地
hosts = ['127.0.0.1']
def snmpWalk(host, oid):
result = os.popen('snmpwalk -v 2c -c public ' + host + ' ' + oid).read()
return result
#snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.2021.5000
#处理回显结果system
def getSystem(host):
system = snmpWalk(host, '.1.3.6.1.4.1.2021.5000.3.1.2.10.103.101.116.119.105.110.105.110.102.111')
if system.find('Hex-STRING:') > 0:
system = "".join(system.split('Hex-STRING:')[1:])
system = "".join(system.split('\n'))
system = "".join(system.split(' '))
system = system.decode("hex")
else:
system = "".join(system.split('STRING: \"')[1:])
system = system[0:len(system)-2]
return system
def main():
for host in hosts:
print('=' * 10 + host + '=' * 10)
print(u"测试信息")
system = getSystem(host)
print system
my_file = 'C:/test/snmpTestinfo'
print ("信息存储到文件: %s"%(my_file)).decode('utf-8').encode('gbk')
if os.path.exists(my_file):
os.remove(my_file)
f = open(my_file, 'a+')
f.write(str(system))
f.close()
if __name__ == '__main__':
main()
用python3.3结合snmpget截取信息
毕业一年多了,一直做cable modem的测试,总是觉得在国内这一行的人才很少,想找个师傅真的很不容易。
苦闷了许久之后,终于决定,自己去写点东西,万一就找到同行了呢?
下面就是本小姐写的第一篇博客,关于在win7下如何用python获取cable modem的设备信息的。
当然用mib browser是非常方便的,但是想到以后可能要做自动化方面的东西,所以就无聊的写了下面的代码。
snmp_get_sysDescr.py
from pysnmp.entity.rfc3413.oneliner import cmdgen
import re
def snmpget():
errIndication, errStatus, errIndex, varBinds = cmdgen.CommandGenerator().getCmd(
cmdgen.CommunityData('my-agent', 'public', 1),
cmdgen.UdpTransportTarget(("192.168.100.1",161)),
'1.3.6.1.2.1.1.1.0'
)
string = str(varBinds[0][1])
str1 = re.search("(<<.*>>)",string)
str2 = re.sub("<<|>>",'',str1.group())
print(re.split('; ',str2))
if __name__ == "__main__":
snmpget()
结果如下:
1 E:Python>python snmp_get_sysDescr.py
2 ['HW_REV: 1.0', 'VENDOR: UNI', 'BOOTR: 2.4.0', 'SW_REV: B5510mp5-S-EU-D230-151021', 'MODEL: TCG220']