From: Serhiy Storchaka Date: Tue, 13 Feb 2018 09:15:21 +0000 (+0200) Subject: [3.6] bpo-32370: Use the correct encoding for ipconfig output in the uuid module... X-Git-Tag: v3.6.5rc1~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3f9d7e0ea30e94c901d13e1d43ff0be1e5dbcb7;p=python [3.6] bpo-32370: Use the correct encoding for ipconfig output in the uuid module. (GH-5608). (#5654) (cherry picked from commit da6c3da6c33c6bf794f741e348b9c6d86cc43ec5) Co-authored-by: Segev Finer --- diff --git a/Lib/uuid.py b/Lib/uuid.py index 3cd67fcfd0..32a48eaeac 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -419,7 +419,7 @@ def _netstat_getnode(): def _ipconfig_getnode(): """Get the hardware address on Windows by running ipconfig.exe.""" - import os, re + import os, re, subprocess dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] try: import ctypes @@ -430,11 +430,13 @@ def _ipconfig_getnode(): pass for dir in dirs: try: - pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') + proc = subprocess.Popen([os.path.join(dir, 'ipconfig'), '/all'], + stdout=subprocess.PIPE, + encoding="oem") except OSError: continue - with pipe: - for line in pipe: + with proc: + for line in proc.stdout: value = line.split(':')[-1].strip().lower() if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): return int(value.replace('-', ''), 16) diff --git a/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst b/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst new file mode 100644 index 0000000000..7f076d45be --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst @@ -0,0 +1,2 @@ +Use the correct encoding for ipconfig output in the uuid module. +Patch by Segev Finer.