[fix] use wmic replace uuid.getnode, because of mac address is not stable

This commit is contained in:
zhji 2026-01-23 00:14:50 +08:00
parent a4885e5602
commit 0401c3f57b
3 changed files with 33 additions and 12 deletions

View File

@ -373,10 +373,17 @@ def get_mac_address():
获取MAC地址
"""
try:
# 获取本机的MAC地址
mac = uuid.getnode()
mac_str = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
return mac_str
result = subprocess.check_output(
'wmic nic where "PhysicalAdapter=True" get MACAddress',
shell=True,
stderr=subprocess.STDOUT,
text=True
)
lines = result.strip().split('\n')
for line in lines:
line = line.strip()
if line and line != 'MACAddress' and ':' in line:
return line
except Exception as e:
logging.error(f"获取MAC地址失败: {e}")
return "00:00:00:00:00:00"

View File

@ -906,10 +906,17 @@ def get_mac_address():
获取MAC地址
"""
try:
# 获取本机的MAC地址
mac = uuid.getnode()
mac_str = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
return mac_str
result = subprocess.check_output(
'wmic nic where "PhysicalAdapter=True" get MACAddress',
shell=True,
stderr=subprocess.STDOUT,
text=True
)
lines = result.strip().split('\n')
for line in lines:
line = line.strip()
if line and line != 'MACAddress' and ':' in line:
return line
except Exception as e:
logging.error(f"获取MAC地址失败: {e}")
return "00:00:00:00:00:00"

View File

@ -56,10 +56,17 @@ def get_mac_address():
获取MAC地址
"""
try:
# 获取本机的MAC地址
mac = uuid.getnode()
mac_str = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
return mac_str
result = subprocess.check_output(
'wmic nic where "PhysicalAdapter=True" get MACAddress',
shell=True,
stderr=subprocess.STDOUT,
text=True
)
lines = result.strip().split('\n')
for line in lines:
line = line.strip()
if line and line != 'MACAddress' and ':' in line:
return line
except Exception as e:
logging.error(f"获取MAC地址失败: {e}")
return "00:00:00:00:00:00"