import uuid
import platform
import subprocess
def get_mac_address():
if platform.system() == "Windows":
try:
output = subprocess.check_output("ipconfig /all").decode("utf-8")
for line in output.splitlines():
if "物理地址" in line:
mac_address = line.split(":")[-1].strip()
return mac_address
except subprocess.CalledProcessError as e:
print(f"获取MAC地址出错: {e}")
return None
elif platform.system() == "Linux":
try:
mac_address = uuid.getnode()
mac_address = ':'.join(("%012X" % mac_address)[i:i + 2] for i in range(0, 12, 2))
return mac_address
except Exception as e:
print(f"获取MAC地址出错: {e}")
return None
else:
print("不支持的操作系统")
return None
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.