【发布时间】:2021-03-21 04:03:38
【问题描述】:
这些值从命令行返回,如下所示:
#~ snmpwalk -v 2c -c someComm localhost .1.3.6.1.2.1.123.1.4.1.12 | grep -i "87 54 2A 63"
SNMPv2-SMI::mib-2.123.1.4.1.12.1.8 = Hex-STRING: 87 54 2A 63
SNMPv2-SMI::mib-2.123.1.4.1.12.1.23 = Hex-STRING: 87 54 2A 63
SNMPv2-SMI::mib-2.123.1.4.1.12.1.32 = Hex-STRING: 87 54 2A 63
SNMPv2-SMI::mib-2.123.1.4.1.12.8.3 = Hex-STRING: 87 54 2A 63
但是当我使用easysnmp时,它们会像这样以unicode形式返回,我无法搜索我需要的行,你能帮我把它转换回来吗?
>>>c = snmp_walk('.1.3.6.1.2.1.123.1.4.1.12', hostname='localhost', community='someComm', version=2)
>>> pprint(c)
[<SNMPVariable value='T*n (contains binary)' (oid='mib-2.123.1.4.1.12.1.1', oid_index='', snmp_type='OCTETSTR')>,
<SNMPVariable value='B& (contains binary)' (oid='mib-2.123.1.4.1.12.1.2', oid_index='', snmp_type='OCTETSTR')>,
...
>>>c= c[1].value
>>> type(c)
<type 'unicode'>
>>> c
u'B\xa2\xb6&'
>>> print(c)
B¢¶&
感谢收看!
【问题讨论】:
-
你知道
u'B\xa2\xb6&'的十六进制数吗? -
按 '87 54 2A 63' 顺序排列的东西,4 个十六进制对。