From dd6cf016c58374cf6af95157b8a4e510a262cb9f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Dec 2022 18:19:51 -0500 Subject: [PATCH] Adding support for darwin. Broken due to sanketsudake/ifconfig-parser#15. --- jaraco/net/devices/darwin.py | 21 +++++++++++++++++++++ setup.cfg | 1 + 2 files changed, 22 insertions(+) create mode 100644 jaraco/net/devices/darwin.py diff --git a/jaraco/net/devices/darwin.py b/jaraco/net/devices/darwin.py new file mode 100644 index 0000000..72ab831 --- /dev/null +++ b/jaraco/net/devices/darwin.py @@ -0,0 +1,21 @@ +import ifparser + +from .base import BaseManager + + +def if_config(): + cfg = subprocess.check_output(['ifconfig']) + return ifparser.Ifcfg(cfg) + + +class Manager(BaseManager): + def get_host_mac_addresses(self): + return map(operator.attrgetter('hwaddr'), self._get_ifaces()) + + def get_host_ip_addresses(self): + return map(operator.attrgetter('ip'), self._get_ifaces()) + + @staticmethod + def _get_ifaces(): + cfg = if_config() + return map(cfg.get_interface, cfg.interfaces) diff --git a/setup.cfg b/setup.cfg index 795ec8c..a697638 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ install_requires = python-dateutil pathvalidate pywin32; sys_platform == 'win32' and python_version < "3.12" + ifparser; sys_platform == 'darwin' jsonpickle != 3.0.0 [options.packages.find]