-
Notifications
You must be signed in to change notification settings - Fork 232
/
log_system_information.py
executable file
·58 lines (50 loc) · 1.99 KB
/
log_system_information.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
import json
import platform
def make_sys_report(anonymous=False, skipUsb=False, skipPackages=False):
def get_usb():
try:
import usb.core
except ImportError:
yield "NoLib"
return
speeds = ["Unknown", "Low", "Full", "High", "Super", "SuperPlus"]
format_hex = lambda val: f"{val:#0{6}x}"
try:
for dev in usb.core.find(find_all=True):
yield {
"port": dev.port_number,
"vendor_id": format_hex(dev.idVendor),
"product_id": format_hex(dev.idProduct),
"speed": speeds[dev.speed] if dev.speed < len(speeds) else dev.speed
}
except usb.core.NoBackendError:
yield "No USB backend found"
result = {
"architecture": ' '.join(platform.architecture()).strip(),
"machine": platform.machine(),
"platform": platform.platform(),
"processor": platform.processor(),
"python_build": ' '.join(platform.python_build()).strip(),
"python_compiler": platform.python_compiler(),
"python_implementation": platform.python_implementation(),
"python_version": platform.python_version(),
"release": platform.release(),
"system": platform.system(),
"version": platform.version(),
"win32_ver": ' '.join(platform.win32_ver()).strip(),
}
if not skipPackages:
from pip._internal.operations.freeze import freeze
result["packages"] = list(freeze(local_only=True))
if not skipUsb:
result["usb"] = list(get_usb())
if not anonymous:
result["uname"] = ' '.join(platform.uname()).strip(),
return result
if __name__ == "__main__":
data = make_sys_report()
with open("log_system_information.json", "w") as f:
json.dump(data, f, indent=4)
print(json.dumps(data, indent=4))
print("System info gathered successfully - saved as \"log_system_information.json\"")