您可以使用该netaddr
软件包。如果您正在使用 Ubuntu/Debian,您可以通过以下方式轻松安装它:
# apt-get install python-netaddr
或者,您可以将其安装pip
在 virtualenv 或 Python3 venv 中:
$ source myenvironment/bin/activate
$ pip install netaddr
然后你可以试试这个:
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from netaddr import *
>>> mac = EUI(0x05056bdafc)
>>>
>>> print mac
00-05-05-6B-DA-FC
>>>
或使用 Python 3:
$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from netaddr import *
>>>
>>>
>>> mac = EUI(0x05056bdafc)
>>>
>>> print (mac)
00-05-05-6B-DA-FC
>>>
>>> mac.dialect = mac_unix
>>>
>>> print (mac)
0:5:5:6b:da:fc
您可以在此处找到更多示例。
希望这可以帮助。祝你好运!