]> granicus.if.org Git - python/commitdiff
Issue #22902: The "ip" command is now used on Linux to determine MAC address
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 30 Nov 2014 18:39:04 +0000 (20:39 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 30 Nov 2014 18:39:04 +0000 (20:39 +0200)
in uuid.getnode().  Pach by Bruno Cauet.

Lib/test/test_uuid.py
Lib/uuid.py
Misc/ACKS
Misc/NEWS

index bfa9f973d77b2374a1c3e90d502220be37d3bdc6..bc83de2211d58b3040fd628c0b134bf2fc9a23e5 100644 (file)
@@ -320,6 +320,12 @@ class TestUUID(unittest.TestCase):
         if node is not None:
             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()
index 9c2a971ae5299eac277b8a7778e91483beecc83e..7b0b413966c0afed021dda8b67275ffad9479063 100644 (file)
@@ -356,6 +356,13 @@ def _ifconfig_getnode():
         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 @@ def getnode():
     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:
index 3d4094cd13a7c4c44a6be75ad247837e5faca0d8..eae72c7591c2f7598f5926df2a6e82346ad7efb5 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -217,6 +217,7 @@ Pierre Carrier
 Terry Carroll
 Edward Catmur
 Lorenzo M. Catucci
+Bruno Cauet
 Donn Cave
 Charles Cazabon
 Jesús Cea Avión
index 7e568c6503938f1a6da0f8e4455b79e986cec4d5..8fb14e0a4f6c92f93b0443baf8cfedc41bcfada5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -191,6 +191,9 @@ Core and Builtins
 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().