Просмотр исходного кода

Merge pull request #538 from exo-explore/macosnetwork

mac os network interface name
Alex Cheema 8 месяцев назад
Родитель
Сommit
1de1b6c930
1 измененных файлов с 21 добавлено и 1 удалено
  1. 21 1
      exo/helpers.py

+ 21 - 1
exo/helpers.py

@@ -246,7 +246,27 @@ def get_interface_priority_and_type(ifname: str) -> Tuple[int, str]:
   if ifname.startswith('lo'):
     return (6, "Loopback")
 
-  # Thunderbolt/10GbE detection
+  # On macOS, use networksetup to accurately identify interface types
+  if psutil.MACOS:
+    try:
+      import subprocess
+      result = subprocess.run(['networksetup', '-listallhardwareports'], capture_output=True, text=True)
+      output = result.stdout
+
+      # Find the hardware port info for this interface
+      for block in output.split('\n\n'):
+        if f'Device: {ifname}' in block:
+          if 'Ethernet' in block or 'LAN' in block:
+            return (4, "Ethernet")
+          elif 'Wi-Fi' in block or 'Airport' in block:
+            return (3, "WiFi")
+          elif 'Thunderbolt' in block:
+            return (5, "Thunderbolt/10GbE")
+    except Exception as e:
+      if DEBUG >= 2:
+        print(f"Error detecting macOS interface type: {e}")
+
+  # Traditional detection for non-macOS systems or fallback
   if ifname.startswith(('tb', 'nx', 'ten')):
     return (5, "Thunderbolt/10GbE")