octet string conversion

Erik Max Francis max at alcyone.com
Mon Jul 28 23:46:05 CEST 2003


Matthew wrote:

> I am working on some software that uses SNMP to get information from
> routers and switches. I am using the pysnmp module (v2.0.8) to do the
> snmp part. The problem that I am having is that when I query a router
> for mac addresses pysnmp returns octetstrings like this:
> 
> \000\002\263\254\264\351
> \010\000 \301F\021
> \010\000 \300\303[
> \000\002\263\254\264\241

I presume these are the repr of the strings you get back.  If so, this
is simply in binary format.  To convert, take the ord of each character
and print the hexadecimal code:

>>> S = '\010\000 \301F\021'
>>> ':'.join(['%x' % ord(x) for x in S])
'8:0:20:c1:46:11'

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Take the slow train / To my destination
\__/  Sandra St. Victor




More information about the Python-list mailing list