[fix] use wmic replace uuid.getnode, because of mac address is not stable
This commit is contained in:
parent
a4885e5602
commit
0401c3f57b
@ -373,10 +373,17 @@ def get_mac_address():
|
|||||||
获取MAC地址
|
获取MAC地址
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 获取本机的MAC地址
|
result = subprocess.check_output(
|
||||||
mac = uuid.getnode()
|
'wmic nic where "PhysicalAdapter=True" get MACAddress',
|
||||||
mac_str = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
|
shell=True,
|
||||||
return mac_str
|
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:
|
except Exception as e:
|
||||||
logging.error(f"获取MAC地址失败: {e}")
|
logging.error(f"获取MAC地址失败: {e}")
|
||||||
return "00:00:00:00:00:00"
|
return "00:00:00:00:00:00"
|
||||||
|
|||||||
@ -906,10 +906,17 @@ def get_mac_address():
|
|||||||
获取MAC地址
|
获取MAC地址
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 获取本机的MAC地址
|
result = subprocess.check_output(
|
||||||
mac = uuid.getnode()
|
'wmic nic where "PhysicalAdapter=True" get MACAddress',
|
||||||
mac_str = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
|
shell=True,
|
||||||
return mac_str
|
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:
|
except Exception as e:
|
||||||
logging.error(f"获取MAC地址失败: {e}")
|
logging.error(f"获取MAC地址失败: {e}")
|
||||||
return "00:00:00:00:00:00"
|
return "00:00:00:00:00:00"
|
||||||
|
|||||||
@ -56,10 +56,17 @@ def get_mac_address():
|
|||||||
获取MAC地址
|
获取MAC地址
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 获取本机的MAC地址
|
result = subprocess.check_output(
|
||||||
mac = uuid.getnode()
|
'wmic nic where "PhysicalAdapter=True" get MACAddress',
|
||||||
mac_str = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
|
shell=True,
|
||||||
return mac_str
|
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:
|
except Exception as e:
|
||||||
logging.error(f"获取MAC地址失败: {e}")
|
logging.error(f"获取MAC地址失败: {e}")
|
||||||
return "00:00:00:00:00:00"
|
return "00:00:00:00:00:00"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user