harden macOS networking port
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
||||
import random
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .firewall import is_admin
|
||||
@@ -41,6 +42,26 @@ def list_nics() -> list[NicMac]:
|
||||
|
||||
Falls back to ``wmic nic`` for hosts without PowerShell 3.0 (Server 2008 R2).
|
||||
"""
|
||||
if sys.platform == "darwin":
|
||||
code, out, _ = _run(["ifconfig"], timeout=10)
|
||||
if code != 0:
|
||||
return []
|
||||
nics: list[NicMac] = []
|
||||
current = ""
|
||||
is_up = False
|
||||
mac = ""
|
||||
for line in out.splitlines():
|
||||
if line and not line.startswith("\t") and ":" in line:
|
||||
if current and is_up and mac:
|
||||
nics.append(NicMac(name=current, mac=mac, description=current))
|
||||
current = line.split(":", 1)[0].strip()
|
||||
is_up = "UP" in line
|
||||
mac = ""
|
||||
elif "\tether " in line:
|
||||
mac = line.strip().split()[1].replace("-", ":")
|
||||
if current and is_up and mac:
|
||||
nics.append(NicMac(name=current, mac=mac, description=current))
|
||||
return nics
|
||||
compat = _win_probe()
|
||||
if not compat.has_net_cmdlets:
|
||||
return _list_nics_wmic()
|
||||
|
||||
Reference in New Issue
Block a user