MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_mac_address

Function get_mac_address

pager_lib/getmac/getmac.py:1692–1900  ·  view source on GitHub ↗

Get an Unicast IEEE 802 MAC-48 address from a local interface or remote host. Only ONE of the first four arguments may be used (``interface``,``ip``, ``ip6``, or ``hostname``). If none of the arguments are selected, the default network interface for the system will be used.

(  # noqa: C901
    interface=None, ip=None, ip6=None, hostname=None, network_request=True
)

Source from the content-addressed store, hash-verified

1690
1691
1692def get_mac_address( # noqa: C901
1693 interface=None, ip=None, ip6=None, hostname=None, network_request=True
1694):
1695 # type: (Optional[str], Optional[str], Optional[str], Optional[str], bool) -> Optional[str]
1696 """
1697 Get an Unicast IEEE 802 MAC-48 address from a local interface or remote host.
1698
1699 Only ONE of the first four arguments may be used
1700 (``interface``,``ip``, ``ip6``, or ``hostname``).
1701 If none of the arguments are selected, the default network interface for
1702 the system will be used.
1703
1704 .. warning::
1705 In getmac 1.0.0, exceptions will be raised if the method cache initialization fails
1706 (in other words, if there are no valid methods found for the type of MAC requested).
1707
1708 .. warning::
1709 You MUST provide :class:`str` typed arguments, REGARDLESS of Python version
1710
1711 .. note::
1712 ``"localhost"`` or ``"127.0.0.1"`` will always return ``"00:00:00:00:00:00"``
1713
1714 .. note::
1715 It is assumed that you are using Ethernet or Wi-Fi. While other protocols
1716 such as Bluetooth may work, this has not been tested and should not be
1717 relied upon. If you need this functionality, please open an issue
1718 (or better yet, a Pull Request ;))!
1719
1720 .. note::
1721 Exceptions raised by methods are handled silently and returned as :obj:`None`.
1722
1723 Args:
1724 interface (str): Name of a local network interface (e.g "Ethernet 3", "eth0", "ens32")
1725 ip (str): Canonical dotted decimal IPv4 address of a remote host (e.g ``192.168.0.1``)
1726 ip6 (str): Canonical shortened IPv6 address of a remote host (e.g ``ff02::1:ffe7:7f19``)
1727 hostname (str): DNS hostname of a remote host (e.g "router1.mycorp.com", "localhost")
1728 network_request (bool): If network requests should be made when attempting to find the
1729 MAC of a remote host. If the ``arping`` command is available, this will be used.
1730 If not, a UDP packet will be sent to the remote host to populate
1731 the ARP/NDP tables for IPv4/IPv6. The port this packet is sent to can
1732 be configured using the module variable ``getmac.PORT``.
1733
1734 Returns:
1735 Lowercase colon-separated MAC address, or :obj:`None` if one could not be
1736 found or there was an error.
1737 """ # noqa: E501
1738
1739 if DEBUG:
1740 import timeit
1741
1742 start_time = timeit.default_timer()
1743
1744 if PY2 or (sys.version_info[0] == 3 and sys.version_info[1] < 7):
1745 global WARNED_UNSUPPORTED_PYTHONS
1746 if not WARNED_UNSUPPORTED_PYTHONS:
1747 warning_string = (
1748 "Support for Python versions < 3.7 is deprecated and will be "
1749 "removed in getmac 1.0.0. If you are stuck on an unsupported "

Callers 1

gmaFunction · 0.90

Calls 11

initialize_method_cacheFunction · 0.85
get_instance_from_cacheFunction · 0.85
_attempt_method_getFunction · 0.85
_swap_method_fallbackFunction · 0.85
get_by_methodFunction · 0.85
_fetch_ip_using_dnsFunction · 0.85
_clean_macFunction · 0.85
warningMethod · 0.80
errorMethod · 0.80
debugMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected