8000 [2.7] bpo-9678: Fix determining the MAC address in the uuid module. (… · python/cpython@f72ad2d · GitHub
[go: up one dir, main page]

Skip to content

Commit f72ad2d

Browse files
[2.7] bpo-9678: Fix determining the MAC address in the uuid module. (GH-4264) (#4270)
* Using ifconfig on NetBSD and OpenBSD. * Using arp on Linux, FreeBSD, NetBSD and OpenBSD. Based on patch by Takayuki Shimizukawa.. (cherry picked from commit ee1a9a2)
1 parent 6a9a331 commit f72ad2d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Lib/uuid.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ def _find_mac(command, args, hw_identifiers, get_index):
339339
def _ifconfig_getnode():
340340
"""Get the hardware address on Unix by running ifconfig."""
341341
# This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
342+
keywords = ('hwaddr', 'ether', 'address:', 'lladdr')
342343
for args in ('', '-a', '-av'):
343-
mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i+1)
344+
mac = _find_mac('ifconfig', args, keywords, lambda i: i+1)
344345
if mac:
345346
return mac
346347

@@ -353,7 +354,20 @@ def _arp_getnode():
353354
return None
354355

355356
# Try getting the MAC addr from arp based on our IP address (Solaris).
356-
return _find_mac('arp', '-an', [ip_addr], lambda i: -1)
357+
mac = _find_mac('arp', '-an', [ip_addr], lambda i: -1)
358+
if mac:
359+
return mac
360+
361+
# This works on OpenBSD
362+
mac = _find_mac('arp', '-an', [ip_addr], lambda i: i+1)
363+
if mac:
364+
return mac
365+
366+
# This works on Linux, FreeBSD and NetBSD
367+
mac = _find_mac('arp', '-an', ['(%s)' % ip_addr],
368+
lambda i: i+2)
369+
if mac:
370+
return mac
357371

358372
def _lanscan_getnode():
359373
"""Get the hardware address on Unix by running lanscan."""
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixed determining the MAC address in the uuid module:
2+
3+
* Using ifconfig on NetBSD and OpenBSD.
4+
* Using arp on Linux, FreeBSD, NetBSD and OpenBSD.
5+
6+
Based on patch by Takayuki Shimizukawa.

0 commit comments

Comments
 (0)
0