MCPcopy Index your code
hub / github.com/python/cpython / _arp_getnode

Function _arp_getnode

Lib/uuid.py:593–619  ·  view source on GitHub ↗

Get the hardware address on Unix by running arp.

()

Source from the content-addressed store, hash-verified

591 return None
592
593def _arp_getnode():
594 """Get the hardware address on Unix by running arp."""
595 import os, socket
596 if not hasattr(socket, "gethostbyname"):
597 return None
598 try:
599 ip_addr = socket.gethostbyname(socket.gethostname())
600 except OSError:
601 return None
602
603 # Try getting the MAC addr from arp based on our IP address (Solaris).
604 mac = _find_mac_near_keyword('arp', '-an', [os.fsencode(ip_addr)], lambda i: -1)
605 if mac:
606 return mac
607
608 # This works on OpenBSD
609 mac = _find_mac_near_keyword('arp', '-an', [os.fsencode(ip_addr)], lambda i: i+1)
610 if mac:
611 return mac
612
613 # This works on Linux, FreeBSD and NetBSD
614 mac = _find_mac_near_keyword('arp', '-an', [os.fsencode('(%s)' % ip_addr)],
615 lambda i: i+2)
616 # Return None instead of 0.
617 if mac:
618 return mac
619 return None
620
621def _lanscan_getnode():
622 """Get the hardware address on Unix by running lanscan."""

Callers

nothing calls this directly

Calls 1

_find_mac_near_keywordFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…