[Python-checkins] cpython: Issue #22902: The "ip" command is now used on Linux to determine MAC address
serhiy.storchaka
python-checkins at python.org
Sun Nov 30 19:41:15 CET 2014
https://hg.python.org/cpython/rev/64bb01bce12c
changeset: 93669:64bb01bce12c
parent: 93666:f385bc6e6e09
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Nov 30 20:39:04 2014 +0200
summary:
Issue #22902: The "ip" command is now used on Linux to determine MAC address
in uuid.getnode(). Pach by Bruno Cauet.
files:
Lib/test/test_uuid.py | 6 ++++++
Lib/uuid.py | 11 +++++++++--
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -321,6 +321,12 @@
self.check_node(node, 'ifconfig')
@unittest.skipUnless(os.name == 'posix', 'requires Posix')
+ def test_ip_getnode(self):
+ node = uuid._ip_getnode()
+ if node is not None:
+ self.check_node(node, 'ip')
+
+ @unittest.skipUnless(os.name == 'posix', 'requires Posix')
def test_arp_getnode(self):
node = uuid._arp_getnode()
if node is not None:
diff --git a/Lib/uuid.py b/Lib/uuid.py
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -356,6 +356,13 @@
if mac:
return mac
+def _ip_getnode():
+ """Get the hardware address on Unix by running ip."""
+ # This works on Linux with iproute2.
+ mac = _find_mac('ip', 'link list', [b'link/ether'], lambda i: i+1)
+ if mac:
+ return mac
+
def _arp_getnode():
"""Get the hardware address on Unix by running arp."""
import os, socket
@@ -538,8 +545,8 @@
if sys.platform == 'win32':
getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode]
else:
- getters = [_unixdll_getnode, _ifconfig_getnode, _arp_getnode,
- _lanscan_getnode, _netstat_getnode]
+ getters = [_unixdll_getnode, _ifconfig_getnode, _ip_getnode,
+ _arp_getnode, _lanscan_getnode, _netstat_getnode]
for getter in getters + [_random_getnode]:
try:
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -217,6 +217,7 @@
Terry Carroll
Edward Catmur
Lorenzo M. Catucci
+Bruno Cauet
Donn Cave
Charles Cazabon
Jesús Cea Avión
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -191,6 +191,9 @@
Library
-------
+- Issue #22902: The "ip" command is now used on Linux to determine MAC address
+ in uuid.getnode(). Pach by Bruno Cauet.
+
- Issue #22960: Add a context argument to xmlrpclib.ServerProxy constructor.
- Issue #22389: Add contextlib.redirect_stderr().
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list