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"