diff --git a/htpclient/initialize.py b/htpclient/initialize.py index 8e1431c..7fdcd8f 100644 --- a/htpclient/initialize.py +++ b/htpclient/initialize.py @@ -63,6 +63,9 @@ def __login(self): if not os.path.isdir("multicast"): os.mkdir("multicast") + def decode_output(self, output): + return output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + def __update_information(self): if not self.config.get_value('uuid'): self.config.set_value('uuid', str(uuid.uuid4())) @@ -72,7 +75,7 @@ def __update_information(self): devices = [] if Initialize.get_os() == 0: # linux output = subprocess.check_output("cat /proc/cpuinfo", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + output = self.decode_output(output) tmp = [] for line in output: line = line.strip() @@ -96,7 +99,7 @@ def __update_information(self): except subprocess.CalledProcessError: # we silently ignore this case on machines where lspci is not present or architecture has no pci bus output = b"" - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + output = self.decode_output(output) for line in output: if not line: continue @@ -104,24 +107,33 @@ def __update_information(self): devices.append(line[1].strip()) elif Initialize.get_os() == 1: # windows - output = subprocess.check_output("wmic cpu get name", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") - for line in output: - line = line.rstrip("\r\n ") - if line == "Name" or not line: - continue - devices.append(line) - output = subprocess.check_output("wmic path win32_VideoController get name", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") - for line in output: - line = line.rstrip("\r\n ") - if line == "Name" or not line: - continue - devices.append(line) + platform_release = platform.uname().release + if platform_release == "" or int(platform_release) >= 10: + processor_information = subprocess.check_output( + 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', + shell=True) + processor_information = self.decode_output(processor_information) + video_controller = subprocess.check_output( + 'powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"', + shell=True) + video_controller = self.decode_output(video_controller) + else: + processor_information = subprocess.check_output( + 'wmic cpu get name', + shell=True) + processor_information = self.decode_output(processor_information) + video_controller = subprocess.check_output('wmic path win32_VideoController get name', shell=True) + video_controller = self.decode_output(video_controller) + + for source in (processor_information, video_controller): + for line in source: + line = line.rstrip("\r\n ") + if line and line != "Name": + devices.append(line) else: # OS X output = subprocess.check_output("system_profiler SPDisplaysDataType -detaillevel mini", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + output = self.decode_output(output) for line in output: line = line.rstrip("\r\n ") if "Chipset Model" not in line: