Skip to content

get_mac_address() returns None by default when connected to corporate VPN #91

@istrupin

Description

@istrupin

Describe the bug
When running the get_mac_address() not connected to VPN, everything works. However, when connected to my corporate VPN (via GlobalProtect), the response is None.

To Reproduce

  1. Connect to corporate VPN
  2. either run get_mac_address() or run getmac -v --debug

Expected behavior
MAC address of default networking device

System info
(please complete the following information):

  • OS name (e.g. Windows 10 x64): macOS Monterey
  • OS Version (e.g. 1804 build 17134): 12.6
  • Python version (e.g. CPython 3.6.5 x64): 3.8.16
  • getmac version (e.g. getmac 0.8.3): 0.94

Additional context
Output with verbose logging:

❯ poetry run getmac -v --debug
Configuration file exists at /Users/istrupinskiy/Library/Application Support/pypoetry, reusing this directory.

Consider moving configuration to /Users/istrupinskiy/Library/Preferences/pypoetry, as support for the legacy directory will be removed in an upcoming release.
DEBUG    Initializing 'default_iface' method cache (platform: 'darwin')
DEBUG    Current method cache: {'ip4': 'None', 'ip6': 'None', 'iface': 'None', 'default_iface': 'DefaultIfaceRouteGetCommand'}
DEBUG    Current fallback cache: {'ip4': '[]', 'ip6': '[]', 'iface': '[]', 'default_iface': '[]'}
DEBUG    Finished initializing 'default_iface' method cache
DEBUG    Attempting get() (method='DefaultIfaceRouteGetCommand', method_type='default_iface', arg='')
DEBUG    Initializing 'iface' method cache (platform: 'darwin')
DEBUG    Current method cache: {'ip4': 'None', 'ip6': 'None', 'iface': 'DarwinNetworksetupIface', 'default_iface': 'DefaultIfaceRouteGetCommand'}
DEBUG    Current fallback cache: {'ip4': '[]', 'ip6': '[]', 'iface': '[<getmac.getmac.IfconfigEther object at 0x10aede7c0>]', 'default_iface': '[]'}
DEBUG    Finished initializing 'iface' method cache
DEBUG    Attempting get() (method='DarwinNetworksetupIface', method_type='iface', arg='utun0')
WARNING  Cached Method 'DarwinNetworksetupIface' failed for 'iface' lookup with process exit code '4' != 1, marking unusable. Exception: Command '['/usr/sbin/networksetup', '-getmacaddress', 'utun0']' returned non-zero exit status 4.
WARNING  Falling back to 'IfconfigEther' for unusable method 'DarwinNetworksetupIface'
DEBUG    Attempting get() (method='IfconfigEther', method_type='iface', arg='utun0')
DEBUG    Method 'DarwinNetworksetupIface' failed for 'iface' lookup
DEBUG    Attempting get() (method='IfconfigEther', method_type='iface', arg='lo')
DEBUG    Method 'IfconfigEther' failed for 'iface' lookup
DEBUG    Raw MAC found: None
DEBUG    getmac took 0.1592 seconds

When specifying an interface I do get a result even with VPN:

❯ poetry run getmac -v --debug --interface en0
Configuration file exists at /Users/istrupinskiy/Library/Application Support/pypoetry, reusing this directory.

Consider moving configuration to /Users/istrupinskiy/Library/Preferences/pypoetry, as support for the legacy directory will be removed in an upcoming release.
DEBUG    Initializing 'iface' method cache (platform: 'darwin')
DEBUG    Current method cache: {'ip4': 'None', 'ip6': 'None', 'iface': 'DarwinNetworksetupIface', 'default_iface': 'None'}
DEBUG    Current fallback cache: {'ip4': '[]', 'ip6': '[]', 'iface': '[<getmac.getmac.IfconfigEther object at 0x10ab677f0>]', 'default_iface': '[]'}
DEBUG    Finished initializing 'iface' method cache
DEBUG    Attempting get() (method='DarwinNetworksetupIface', method_type='iface', arg='en0')
DEBUG    Raw MAC found: 3c:22:fb:bf:87:c9
DEBUG    getmac took 0.0965 seconds
3c:22:fb:bf:87:c9

I'd like to figure out how to get the MAC address without specifying a network interface as I am using a 3rd party library that uses this pattern, and I do not have access to modify their code. (I also need it to run on a variety of runtimes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions