Commit f72ad2d3 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

[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 ee1a9a2b)
parent 6a9a331b
...@@ -339,8 +339,9 @@ def _find_mac(command, args, hw_identifiers, get_index): ...@@ -339,8 +339,9 @@ def _find_mac(command, args, hw_identifiers, get_index):
def _ifconfig_getnode(): def _ifconfig_getnode():
"""Get the hardware address on Unix by running ifconfig.""" """Get the hardware address on Unix by running ifconfig."""
# This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes. # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
keywords = ('hwaddr', 'ether', 'address:', 'lladdr')
for args in ('', '-a', '-av'): for args in ('', '-a', '-av'):
mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i+1) mac = _find_mac('ifconfig', args, keywords, lambda i: i+1)
if mac: if mac:
return mac return mac
...@@ -353,7 +354,20 @@ def _arp_getnode(): ...@@ -353,7 +354,20 @@ def _arp_getnode():
return None return None
# Try getting the MAC addr from arp based on our IP address (Solaris). # Try getting the MAC addr from arp based on our IP address (Solaris).
return _find_mac('arp', '-an', [ip_addr], lambda i: -1) mac = _find_mac('arp', '-an', [ip_addr], lambda i: -1)
if mac:
return mac
# This works on OpenBSD
mac = _find_mac('arp', '-an', [ip_addr], lambda i: i+1)
if mac:
return mac
# This works on Linux, FreeBSD and NetBSD
mac = _find_mac('arp', '-an', ['(%s)' % ip_addr],
lambda i: i+2)
if mac:
return mac
def _lanscan_getnode(): def _lanscan_getnode():
"""Get the hardware address on Unix by running lanscan.""" """Get the hardware address on Unix by running lanscan."""
......
Fixed determining the MAC address in the uuid module:
* Using ifconfig on NetBSD and OpenBSD.
* Using arp on Linux, FreeBSD, NetBSD and OpenBSD.
Based on patch by Takayuki Shimizukawa.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment