标签:模块 img summary split() replace conf bin spl def
方法一:
借助uuid模块
def get_mac_address():
import uuid
node = uuid.getnode()
mac = uuid.UUID(int = node).hex[-12:]
return mac
方法二:
按操作系统平台来:
def get_mac_address():
‘‘‘
@summary: return the MAC address of the computer
‘‘‘
import sys
import os
mac = None
if sys.platform == "win32":
for line in os.popen("ipconfig /all"):
print line
if line.lstrip().startswith("Physical Address"):
mac = line.split(":")[1].strip().replace("-", ":")
break
else:
for line in os.popen("/sbin/ifconfig"):
if ‘Ether‘ in line:
mac = line.split()[4]
break
return mac
个人推荐方法一,简单通用
标签:模块 img summary split() replace conf bin spl def
原文地址:https://www.cnblogs.com/jubing/p/10968592.html