Search code examples
pythonnet-snmp

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.


Solution

  • 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])