From 0401c3f57bccab0b27a1f02427aa3d8de511e08c Mon Sep 17 00:00:00 2001 From: zhji Date: Fri, 23 Jan 2026 00:14:50 +0800 Subject: [PATCH] [fix] use wmic replace uuid.getnode, because of mac address is not stable --- python/hfc/cali.py | 15 +++++++++++---- python/hfc/hfc.py | 15 +++++++++++---- python/hfc/license_generator.py | 15 +++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/python/hfc/cali.py b/python/hfc/cali.py index 70a5f31..8ab2504 100644 --- a/python/hfc/cali.py +++ b/python/hfc/cali.py @@ -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" diff --git a/python/hfc/hfc.py b/python/hfc/hfc.py index 63ae9af..bd5c011 100644 --- a/python/hfc/hfc.py +++ b/python/hfc/hfc.py @@ -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" diff --git a/python/hfc/license_generator.py b/python/hfc/license_generator.py index c3504fa..48f6552 100644 --- a/python/hfc/license_generator.py +++ b/python/hfc/license_generator.py @@ -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"