bpo-32370: Use the correct encoding for ipconfig output in the uuid module. (GH-5608)

This commit is contained in:
Segev Finer 2018-02-13 08:29:54 +02:00 committed by Serhiy Storchaka
parent b7e2d67f7c
commit da6c3da6c3
2 changed files with 8 additions and 4 deletions

View file

@ -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)