NET-SNMP + Python Mac地址显示为\ x00 \

时间:2016-02-05 23:17:46

标签: python net-snmp

嘿我试图通过ipNetToMediaPhysAddress获取MAC地址,这在使用netsnmp.snmpget命令时工作正常但是当将其保存到变量(元组?)并通过“print”打印出来时,mac-address看起来像这样。

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

代码看起来像这样,

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

那我该怎么办?我只是希望它看起来像普通的MAC地址。

1 个答案:

答案 0 :(得分:1)

也许调用hexlify就足够了

from binascii import hexlify

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