octet string conversion

Terry Reedy tjreedy at udel.edu
Mon Jul 28 16:53:23 EDT 2003


"Matthew" <ruach at chpc.utah.edu> wrote in message
news:ec1162c7.0307281214.50b68373 at posting.google.com...
> 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
>
> what I need though is hex strings like this:
>
> 0:e0:7d:de:5:48
> 0:e0:7d:c8:dc:9f
> 8:0:36:4:3b:de
> 0:80:ad:3a:9e:2b
>
> Can anyone tell me how to convert the octet strings to hex strings?

Is this what you want?
>>> s=repr('\000\002\263\254\264\351').replace(r'\x', ':')
>>> s
"':00:02:b3:ac:b4:e9'" # double " single ' ... single ' double "
>>> s[2:-1]
'00:02:b3:ac:b4:e9'

Terry J. Reedy







More information about the Python-list mailing list