bpo-32370: Use the correct encoding for ipconfig output in the uuid m… · python/cpython@9b5a90b (original) (raw)

Original file line number Diff line number Diff line change
@@ -468,7 +468,7 @@ def _netstat_getnode():
468 468
469 469 def _ipconfig_getnode():
470 470 """Get the hardware address on Windows by running ipconfig.exe."""
471 -import os, re
471 +import os, re, subprocess
472 472 first_local_mac = None
473 473 dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
474 474 try:
@@ -480,11 +480,13 @@ def _ipconfig_getnode():
480 480 pass
481 481 for dir in dirs:
482 482 try:
483 -pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
483 +proc = subprocess.Popen([os.path.join(dir, 'ipconfig'), '/all'],
484 +stdout=subprocess.PIPE,
485 +encoding="oem")
484 486 except OSError:
485 487 continue
486 -with pipe:
487 -for line in pipe:
488 +with proc:
489 +for line in proc.stdout:
488 490 value = line.split(':')[-1].strip().lower()
489 491 if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
490 492 mac = int(value.replace('-', ''), 16)