简体   繁体   中英

NET-SNMP + Python Mac Address shows as \x00\

Hey Im trying to get the MAC-address via ipNetToMediaPhysAddress which works fine when using the netsnmp.snmpget command but when saving that into a variable(tuple?) and printing it out via "print" the mac-address looks like this.

('\\x00\\n\\xb7\\x9c\\x93\\x80',)

Code looks like this,

mac = netsnmp.Varbind("ipNetToMediaPhysAddress."+i+"."+ipadd)
macadd = netsnmp.snmpget(mac, Version = 2, DestHost = ip, Community = comm)
print '%-15s' % macadd

So what do I need to do? I just want it to look like a normal MAC address.

Maybe a call to hexlify is enough

from binascii import hexlify

mac = netsnmp.Varbind("ipNetToMediaPhysAddress."+i+"."+ipadd)
macadd = netsnmp.snmpget(mac, Version = 2, DestHost = ip, Community = comm)
print hexlify(macadd[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM