可以使用netaddr
包。如果你在Ubuntu/Debian的工作,你可以很容易地安裝它是這樣的:
$ source myenvironment/bin/activate
$ pip install netaddr
那麼你可以試試這個:
# apt-get install python-netaddr
或者,你可以在virtualenv中或Python3 VENV與pip
安裝:
$ 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
你可以找到更多的例子here。
希望這會有所幫助。祝你好運!
謝謝你的幫助。我犯了把十六進制地址放在引號內的錯誤,這就是爲什麼當我第一次嘗試時它不起作用。感謝您的協助。 – clonerworks 2014-10-11 03:14:23