Kaydet (Commit) da6c3da6 authored tarafından Segev Finer's avatar Segev Finer Kaydeden (comit) Serhiy Storchaka

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

üst b7e2d67f
...@@ -468,7 +468,7 @@ def _netstat_getnode(): ...@@ -468,7 +468,7 @@ def _netstat_getnode():
def _ipconfig_getnode(): def _ipconfig_getnode():
"""Get the hardware address on Windows by running ipconfig.exe.""" """Get the hardware address on Windows by running ipconfig.exe."""
import os, re import os, re, subprocess
first_local_mac = None first_local_mac = None
dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
try: try:
...@@ -480,11 +480,13 @@ def _ipconfig_getnode(): ...@@ -480,11 +480,13 @@ def _ipconfig_getnode():
pass pass
for dir in dirs: for dir in dirs:
try: 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: except OSError:
continue continue
with pipe: with proc:
for line in pipe: for line in proc.stdout:
value = line.split(':')[-1].strip().lower() value = line.split(':')[-1].strip().lower()
if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
mac = int(value.replace('-', ''), 16) mac = int(value.replace('-', ''), 16)
......
Use the correct encoding for ipconfig output in the uuid module.
Patch by Segev Finer.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment