summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-04 07:37:32 (GMT)
committerGitHub <noreply@github.com>2017-11-04 07:37:32 (GMT)
commitee1a9a2b78d5b6bb1a8148fc5fcf365e6d4e9e67 (patch)
tree978182d729335256f441b297f9f1a86ee1b4702e /Lib
parent93952f881500053057c2e08c4b253ac61233d7db (diff)
downloadcpython-ee1a9a2b78d5b6bb1a8148fc5fcf365e6d4e9e67.zip
cpython-ee1a9a2b78d5b6bb1a8148fc5fcf365e6d4e9e67.tar.gz
cpython-ee1a9a2b78d5b6bb1a8148fc5fcf365e6d4e9e67.tar.bz2
bpo-9678: Fix determining the MAC address in the uuid module. (#4264)
* Using ifconfig on NetBSD and OpenBSD. * Using arp on Linux, FreeBSD, NetBSD and OpenBSD. Based on patch by Takayuki Shimizukawa.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/uuid.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 3123ff8..020c6e7 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -370,8 +370,9 @@ def _find_mac(command, args, hw_identifiers, get_index):
def _ifconfig_getnode():
"""Get the hardware address on Unix by running ifconfig."""
# This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
+ keywords = (b'hwaddr', b'ether', b'address:', b'lladdr')
for args in ('', '-a', '-av'):
- mac = _find_mac('ifconfig', args, [b'hwaddr', b'ether'], lambda i: i+1)
+ mac = _find_mac('ifconfig', args, keywords, lambda i: i+1)
if mac:
return mac
@@ -391,7 +392,20 @@ def _arp_getnode():
return None
# Try getting the MAC addr from arp based on our IP address (Solaris).
- return _find_mac('arp', '-an', [os.fsencode(ip_addr)], lambda i: -1)
+ mac = _find_mac('arp', '-an', [os.fsencode(ip_addr)], lambda i: -1)
+ if mac:
+ return mac
+
+ # This works on OpenBSD
+ mac = _find_mac('arp', '-an', [os.fsencode(ip_addr)], lambda i: i+1)
+ if mac:
+ return mac
+
+ # This works on Linux, FreeBSD and NetBSD
+ mac = _find_mac('arp', '-an', [os.fsencode('(%s)' % ip_addr)],
+ lambda i: i+2)
+ if mac:
+ return mac
def _lanscan_getnode():
"""Get the hardware address on Unix by running lanscan."""