summaryrefslogtreecommitdiff
path: root/Lib/uuid.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-30 20:39:04 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-30 20:39:04 +0200
commitac4aa7b6aad76b404ed1e695b3130988d87fb39f (patch)
treeed6e8286e1a33dc271169fbcd42101544b4143fa /Lib/uuid.py
parent16e802f4aed9db71a2e25fa25daa8fed0fc2e539 (diff)
downloadcpython-git-ac4aa7b6aad76b404ed1e695b3130988d87fb39f.tar.gz
Issue #22902: The "ip" command is now used on Linux to determine MAC address
in uuid.getnode(). Pach by Bruno Cauet.
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r--Lib/uuid.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 9c2a971ae5..7b0b413966 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -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: