1
2
3
4
5
6
7
8
9
#!/usr/bin/env python

import uuid
def get_mac_address():
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
return ":".join([mac[e:e+2] for e in range(0,11,2)])

if __name__== '__main__':
print("mac:%s " % get_mac_address())

保存到文件mac.py,运行该脚本:

1
python ./mac.py

输出结果:

1
mac:f4:5c:89:a5:09:25

可以和ifconfig命令获取的MAC地址对比一下: