0

The values are coming back from the commandline like this:

#~ 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

But when I use easysnmp, they are coming back as unicode like this and I cannot search for the lines I need, can you help me convert it back?

>>>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¢¶&

Thanks for looking!

klaypigeon
  • 97
  • 2
  • 8

1 Answers1

0

Following guidance from How to convert an int to a hex string?, I was able to convert the values from unicode back to hex pairs. Here is a snippet:

>>> myStr = ""
>>> for b in c:
...   myStr += ("%0.2X" % ord(b)) + " "
...
>>> myStr.strip()
'A8 D7 66 BC'
klaypigeon
  • 97
  • 2
  • 8