Python: MAC 地址转换

方法一:

pip install netaddr

from netaddr import *
mac = EUI(0x05056bdafc)
print (mac)
mac.dialect = mac_unix
print (mac)

方法二:

from pysnmp.smi import builder
mibBuilder = builder.MibBuilder()
MacAddress, = mibBuilder.importSymbols('SNMPv2-TC', 'MacAddress')
macAddress = MacAddress(hexValue='05056bdafc'.zfill(12))
macAddress.prettyPrint()

方法三:

mac = '05056bdafc'.zfill(12)
':'.join([ mac[i:i+2] for i in range(0, 12, 2) ])
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注