Skip to content

Commit 9a31c9a

Browse files
committed
Test MAC address libraries with different platforms and locales
1 parent 5fae247 commit 9a31c9a

2 files changed

Lines changed: 251 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Compare MAC Address Methods
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [compare-mac-methods]
6+
jobs:
7+
compare-mac-methods-ubuntu:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
max-parallel: 3
11+
matrix:
12+
test-locale: ['en_US.UTF-8', 'es_MX.UTF-8', 'de_DE.UTF-8', 'pt_BR.UTF-8', 'fr_FR.UTF-8', 'ar_SA.UTF-8', 'zh_TW.UTF-8']
13+
env:
14+
LANG: ${{ matrix.test-locale }}
15+
LC_ALL: ${{ matrix.test-locale }}
16+
steps:
17+
- uses: actions/checkout@v6
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v7
20+
with:
21+
python-version: 3.9
22+
- name: Set up different locales on Ubuntu
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y locales
26+
sudo locale-gen ${{ matrix.test-locale }}
27+
sudo update-locale LANG=${{ matrix.test-locale }} LC_ALL=${{ matrix.test-locale }}
28+
- name: Install dependencies
29+
run: |
30+
uv pip install ifcfg getmac
31+
- name: Linux test locale ${{ matrix.test-locale }}
32+
env:
33+
LANG: ${{ matrix.test-locale }}
34+
LC_ALL: ${{ matrix.test-locale }}
35+
run: uv run scripts/compare_mac_methods.py
36+
compare-mac-methods-macos:
37+
runs-on: macos-latest
38+
strategy:
39+
max-parallel: 3
40+
matrix:
41+
test-locale: ['en_US.UTF-8', 'es_MX.UTF-8', 'de_DE.UTF-8', 'pt_BR.UTF-8', 'fr_FR.UTF-8', 'ar_SA.UTF-8', 'zh_TW.UTF-8']
42+
env:
43+
LANG: ${{ matrix.test-locale }}
44+
LC_ALL: ${{ matrix.test-locale }}
45+
steps:
46+
- uses: actions/checkout@v6
47+
- name: Install uv
48+
uses: astral-sh/setup-uv@v7
49+
with:
50+
python-version: 3.9
51+
- name: Install dependencies
52+
run: |
53+
uv pip install ifcfg getmac
54+
- name: Mac test locale ${{ matrix.test-locale }}
55+
env:
56+
LANG: ${{ matrix.test-locale }}
57+
LC_ALL: ${{ matrix.test-locale }}
58+
run: uv run scripts/compare_mac_methods.py
59+
compare-mac-methods-windows:
60+
runs-on: windows-latest
61+
strategy:
62+
max-parallel: 3
63+
matrix:
64+
pair:
65+
- test-locale: en_US.UTF-8
66+
test-locale-id: en-US
67+
- test-locale: es_MX.UTF-8
68+
test-locale-id: es-MX
69+
- test-locale: de_DE.UTF-8
70+
test-locale-id: de-DE
71+
- test-locale: pt_BR.UTF-8
72+
test-locale-id: pt-BR
73+
- test-locale: fr_FR.UTF-8
74+
test-locale-id: fr-FR
75+
- test-locale: ar_SA.UTF-8
76+
test-locale-id: ar-SA
77+
- test-locale: zh_TW.UTF-8
78+
test-locale-id: zh-TW
79+
steps:
80+
- uses: actions/checkout@v6
81+
- name: Install uv
82+
uses: astral-sh/setup-uv@v7
83+
with:
84+
python-version: 3.9
85+
- name: Install dependencies
86+
run: |
87+
uv pip install ifcfg getmac
88+
- name: Set Windows System Locale and Culture
89+
run: |
90+
Install-Language -Language ${{ matrix.pair.test-locale-id }}
91+
Set-WinSystemLocale -SystemLocale ${{ matrix.pair.test-locale-id }}
92+
Set-Culture -CultureInfo ${{ matrix.pair.test-locale-id }}
93+
shell: pwsh
94+
- name: Windows test locale ${{ matrix.pair.test-locale }}
95+
env:
96+
LANG: ${{ matrix.pair.test-locale }}
97+
LC_ALL: ${{ matrix.pair.test-locale }}
98+
run: uv run scripts/compare_mac_methods.py

scripts/compare_mac_methods.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Comparison script to test ifcfg vs getmac behavior
4+
"""
5+
import locale
6+
import os
7+
import platform
8+
import sys
9+
10+
11+
def get_system_language():
12+
"""Get system language settings"""
13+
try:
14+
# Try to get system language settings
15+
lang_info = {
16+
"locale": locale.getlocale(),
17+
"default_locale": locale.getdefaultlocale(),
18+
"environment": {},
19+
}
20+
21+
# Check environment variables
22+
for var in ["LANG", "LC_ALL", "LC_MESSAGES", "LANGUAGE"]:
23+
if var in os.environ:
24+
lang_info["environment"][var] = os.environ[var]
25+
26+
return lang_info
27+
except Exception as e:
28+
return {"error": str(e)}
29+
30+
31+
def get_ifcfg_macs():
32+
"""Get MAC addresses using ifcfg"""
33+
try:
34+
import ifcfg
35+
36+
interfaces = ifcfg.interfaces().values()
37+
results = {}
38+
for iface in interfaces:
39+
ether = iface.get("ether")
40+
if ether:
41+
results[iface.get("device", "unknown")] = ether
42+
return results
43+
except Exception as e:
44+
return {"error": str(e)}
45+
46+
47+
def get_getmac_macs():
48+
"""Get MAC addresses using getmac"""
49+
try:
50+
import getmac
51+
52+
results = {}
53+
54+
# Default interface
55+
try:
56+
mac = getmac.get_mac_address()
57+
if mac:
58+
results["default"] = mac
59+
except Exception as e:
60+
results["default_error"] = str(e)
61+
62+
# Common interfaces
63+
common_interfaces = ["eth0", "en0", "wlan0", "wi-fi", "Ethernet"]
64+
for interface in common_interfaces:
65+
try:
66+
mac = getmac.get_mac_address(interface=interface)
67+
if mac:
68+
results[interface] = mac
69+
except Exception as e:
70+
results[f"{interface}_error"] = str(e)
71+
72+
return results
73+
except Exception as e:
74+
return {"error": str(e)}
75+
76+
77+
def main():
78+
print(f"Platform: {platform.platform()}")
79+
print(f"System: {platform.system()}")
80+
print(f"Python: {sys.version}")
81+
82+
# Get and display system language information
83+
print(f"\n=== System Language Information ===")
84+
lang_info = get_system_language()
85+
for key, value in lang_info.items():
86+
if key == "environment":
87+
print(f"{key}:")
88+
for env_var, env_value in value.items():
89+
print(f" {env_var}: {env_value}")
90+
else:
91+
print(f"{key}: {value}")
92+
print()
93+
94+
print("=== ifcfg results ===")
95+
ifcfg_results = get_ifcfg_macs()
96+
for interface, mac in ifcfg_results.items():
97+
print(f"{interface}: {mac}")
98+
print()
99+
100+
print("=== getmac results ===")
101+
getmac_results = get_getmac_macs()
102+
for interface, mac in getmac_results.items():
103+
print(f"{interface}: {mac}")
104+
print()
105+
106+
# Compare default interfaces
107+
ifcfg_default = ifcfg_results.get("eth0") or next(
108+
iter(ifcfg_results.values()), None
109+
)
110+
getmac_default = getmac_results.get("default")
111+
112+
print("=== Comparison ===")
113+
print(f"ifcfg default: {ifcfg_default}")
114+
print(f"getmac default: {getmac_default}")
115+
print(f"Match: {ifcfg_default == getmac_default}")
116+
117+
# Additional analysis
118+
print(f"\n=== Analysis ===")
119+
ifcfg_count = len(
120+
[
121+
v
122+
for v in ifcfg_results.values()
123+
if not isinstance(v, str) or not v.startswith("error")
124+
]
125+
)
126+
getmac_count = len(
127+
[
128+
v
129+
for v in getmac_results.values()
130+
if not isinstance(v, str) or not v.startswith("error")
131+
]
132+
)
133+
print(f"ifcfg found {ifcfg_count} interfaces")
134+
print(f"getmac found {getmac_count} interfaces")
135+
136+
# Check for errors
137+
ifcfg_errors = [
138+
v
139+
for v in ifcfg_results.values()
140+
if isinstance(v, str) and v.startswith("error")
141+
]
142+
getmac_errors = [
143+
v
144+
for v in getmac_results.values()
145+
if isinstance(v, str) and v.startswith("error")
146+
]
147+
148+
print(f"ifcfg errors: {len(ifcfg_errors)}")
149+
print(f"getmac errors: {len(getmac_errors)}")
150+
151+
152+
if __name__ == "__main__":
153+
main()

0 commit comments

Comments
 (0)