diff options
author | Segev Finer <segev208@gmail.com> | 2018-02-13 06:29:54 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2018-02-13 06:29:54 (GMT) |
commit | da6c3da6c33c6bf794f741e348b9c6d86cc43ec5 (patch) | |
tree | 187b3cf88f536fa7aad64369f47e895bfdc77c90 /Lib/uuid.py | |
parent | b7e2d67f7c035f09c921ca4e7a36529cd502ccf7 (diff) | |
download | cpython-da6c3da6c33c6bf794f741e348b9c6d86cc43ec5.zip cpython-da6c3da6c33c6bf794f741e348b9c6d86cc43ec5.tar.gz cpython-da6c3da6c33c6bf794f741e348b9c6d86cc43ec5.tar.bz2 |
bpo-32370: Use the correct encoding for ipconfig output in the uuid module. (GH-5608)
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r-- | Lib/uuid.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py index ef7b3b5..9cb73e8 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -468,7 +468,7 @@ def _netstat_getnode(): def _ipconfig_getnode(): """Get the hardware address on Windows by running ipconfig.exe.""" - import os, re + import os, re, subprocess first_local_mac = None dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] try: @@ -480,11 +480,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): mac = int(value.replace('-', ''), 16) |