WOLFIE_OG

Untitled

Apr 17th, 2025
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.50 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2. import psutil
  3. import math
  4. import subprocess
  5.  
  6. def getSize(bytes: int):
  7.     if bytes == 0:
  8.         return {"str": "0B", "int": 0, "name": "B"}
  9.     size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
  10.     i = int(math.floor(math.log(bytes, 1024)))
  11.     p = math.pow(1024, i)
  12.     s = round(bytes / p, 2)
  13.     return {"str": f"{s} {size_name[i]}", "int": s, "name": size_name[i]}
  14.  
  15. class Partition:
  16.     def __init__(self):
  17.         self.mount_point: str = None
  18.         self.capacity: str = None
  19.         self.used: str = None
  20.         self.free: str = None
  21.         self.bitlocker: str = None
  22.  
  23. class Drive:
  24.     def __init__(self):
  25.         self.model: str = None
  26.         self.sn: str = None
  27.         self.capacity: str = None
  28.         self.paritions: list[Partition] = []
  29.  
  30. class Drives:
  31.     def __init__(self):
  32.         self.nvme: list[Drive] = []
  33.         self.sata: list[Drive] = []
  34.  
  35. class GPU:
  36.     def __init__(self):
  37.         self.name: str = None
  38.         self.vram: str = None
  39.         self.clock: str = None
  40.         self.m_clock: str = None
  41.  
  42. class RAMStick:
  43.     def __init__(self):
  44.         self.mod_num: int = 0
  45.         self.size: str = None
  46.         self.mem_type: str = None
  47.         self.speed: str = None
  48.         self.brand: str = None
  49.         self.pn: str = None
  50.  
  51. class RAM:
  52.     def __init__(self):
  53.         self.total: str = None
  54.         self.sticks: list[RAMStick] = []
  55.  
  56. class Motherboard:
  57.     def __init__(self):
  58.         self.model: str = None
  59.         self.chipset: str = None
  60.         self.usb_version: str = None
  61.         self.tpm: str = None
  62.  
  63. class CPU:
  64.     def __init__(self):
  65.         self.name: str = None
  66.         self.cores: int = 0
  67.         self.lcores: int = 0
  68.         self.hz: str = None
  69.  
  70. class System:
  71.     def __init__(self):
  72.         self.mobo: Motherboard = Motherboard()
  73.         self.gpu: GPU = GPU()
  74.         self.ram: RAM = RAM()
  75.         self.cpu: CPU = CPU()
  76.         self.drives: Drives = Drives()
  77.         self.name: str = None
  78.         self.os: str = None
  79.         self.brand: str = None
  80.         self.uefi: str = None
  81.         self.sb: str = None
  82.  
  83. system = System()
  84.  
  85. def wait_close():
  86.     input("Press any key to close.")
  87.     exit(1)
  88.  
  89. #tree = ET.parse("DESKTOP-1OS8C68.XML")
  90. tree = ET.parse("Desktop-T493T.XML")
  91.  
  92. root = tree.getroot()
  93.  
  94. sub_nodes = root[0].find("SubNodes")
  95.  
  96. if sub_nodes is None:
  97.     print("Can't find SubNodes element!")
  98.     wait_close()
  99.  
  100. computer_node = root.find("COMPUTER")
  101. for c in computer_node:
  102.     if c.tag == "Property":
  103.         d = c.find("Description").text
  104.         match c.find("Entry").text:
  105.             case "Computer Name":
  106.                 system.name = d
  107.         # system.brand = d
  108.             case "Operating System":
  109.                 system.os = d
  110.             case "UEFI Boot":
  111.                 system.uefi = d
  112.             case "Secure Boot":
  113.                 system.sb = d
  114.  
  115. mobo_node = sub_nodes.find("MOBO")
  116. for m in mobo_node:
  117.     if m.tag == "Property":
  118.         d = m.find("Description").text
  119.         match m.find("Entry").text:
  120.             case "Motherboard Model":
  121.                 system.mobo.model = d
  122.             case "Motherboard Chipset":
  123.                 system.mobo.chipset = d
  124.             case "USB Version Supported":
  125.                 system.mobo.usb_version = d
  126.             case "Trusted Platform Module (TPM) Chip":
  127.                 system.mobo.tpm = d
  128.  
  129. ram_node = sub_nodes.find("MEMORY")
  130. for r in ram_node:
  131.     if r.tag == "Property":
  132.         d = r.find("Description").text
  133.         match r.find("Entry").text:
  134.             case "Total Memory Size":
  135.                 system.ram.total = d
  136.  
  137.     if r.tag == "SubNode":
  138.         ram = RAMStick()
  139.         for s in r:
  140.             if s.tag == "Property":
  141.                 d = s.find("Description").text
  142.                 match s.find("Entry").text:
  143.                     case "Module Number":
  144.                         ram.mod_num = d
  145.                     case "Module Part Number":
  146.                         ram.pn = d
  147.                     case "Module Manufacturer":
  148.                         ram.brand = d
  149.                     case "Memory Type":
  150.                         ram.mem_type = d
  151.                     case "Memory Speed":
  152.                         ram.speed = d
  153.                     case "Module Size":
  154.                         ram.size = d
  155.         system.ram.sticks.append(ram)
  156.        
  157. cpu_node = sub_nodes.find("CPU")
  158. for c in cpu_node:
  159.     if c.tag == "Property":
  160.         d = c.find("Description").text
  161.         match c.find("Entry").text:
  162.             case "Number Of Processor Cores":
  163.                 system.cpu.cores = d
  164.             case "Number Of Logical Processors":
  165.                 system.cpu.lcores = d
  166.  
  167.     if c.tag == "SubNode":
  168.         for _c in c:
  169.             if _c.tag == "Property":
  170.                 d = _c.find("Description").text
  171.                 match _c.find("Entry").text:
  172.                     case "Processor Name":
  173.                         system.cpu.name = d
  174.                     case "Original Processor Frequency [MHz]":
  175.                         system.cpu.hz = f'{(int(d) / 1000)} Ghz'
  176.  
  177. gpu_node = sub_nodes.find("VIDEO")
  178. for g in gpu_node:
  179.     if g.tag == "SubNode":
  180.         for _g in g:
  181.             if _g.tag == "Property":
  182.                 d = _g.find("Description").text
  183.                 match _g.find("Entry").text:
  184.                     case "Video Card":
  185.                         system.gpu.name = d
  186.                     case "Video Memory":
  187.                         system.gpu.vram = d
  188.                     case "Graphics Processor Clock":
  189.                         system.gpu.clock = d
  190.                     case "Graphics Memory Clock":
  191.                         system.gpu.m_clock = d
  192.  
  193. drives_node = sub_nodes.find("DRIVES")
  194.  
  195. nvme_drives = drives_node[3]
  196. for n_drive in nvme_drives:
  197.     if n_drive.tag == "SubNode":
  198.         drive = Drive()
  199.         for p in n_drive:
  200.             if p.tag == "Property":
  201.                 d = p.find("Description").text
  202.                 match p.find("Entry").text:
  203.                     case "Drive Model":
  204.                         drive.model = d
  205.                     case "Drive Serial Number":
  206.                         drive.sn = d
  207.                     case "Drive Capacity":
  208.                         drive.capacity = d
  209.                     case "Drive Letter(s)":
  210.                         for l in d.split(","):
  211.                             part = Partition()
  212.                             part.capacity = getSize(psutil.disk_usage(l).total).get("str")
  213.                             part.free = getSize(psutil.disk_usage(l).free).get("str")
  214.                             part.used = getSize(psutil.disk_usage(l).used).get("str")
  215.                             part.mount_point = l
  216.                             proc = subprocess.Popen(args=f"manage-bde -status {l}", stdout=subprocess.PIPE)
  217.                             out, err = proc.communicate()
  218.                             for line in out.decode("utf-8").split("\n"):
  219.                                 if "Protection Status:" in line:
  220.                                     part.bitlocker = line.split(":")[1].strip()
  221.                             drive.paritions.append(part)
  222.         system.drives.nvme.append(drive)
  223.        
  224. sata_drives = drives_node[2]
  225. for s_drive in sata_drives:
  226.     if s_drive.tag == "SubNode":
  227.         drive = Drive()
  228.         for p in s_drive:
  229.             if p.tag == "Property":
  230.                 d = p.find("Description").text
  231.                 match p.find("Entry").text:
  232.                     case "Drive Model":
  233.                         drive.model = d
  234.                     case "Drive Serial Number":
  235.                         drive.sn = d
  236.                     case "Drive Capacity":
  237.                         drive.capacity = d
  238.                     case "Drive Letter(s)":
  239.                         for l in d.split(","):
  240.                             part = Partition()
  241.                             part.capacity = getSize(psutil.disk_usage(l).total).get("str")
  242.                             part.free = getSize(psutil.disk_usage(l).free).get("str")
  243.                             part.used = getSize(psutil.disk_usage(l).used).get("str")
  244.                             part.mount_point = l
  245.                             proc = subprocess.Popen(args=f"manage-bde -status {l}", stdout=subprocess.PIPE)
  246.                             out, err = proc.communicate()
  247.                             for line in out.decode("utf-8").split("\n"):
  248.                                 if "Protection Status:" in line:
  249.                                     part.bitlocker = line.split(":")[1].strip()
  250.                             drive.paritions.append(part)
  251.         system.drives.sata.append(drive)
  252.  
  253. ram_sticks = []
  254.  
  255. for stick in system.ram.sticks:
  256.     ram_sticks.append(
  257.         f"""
  258.            Module Number:      {stick.mod_num}
  259.            Part Number:        {stick.pn}
  260.            Brand:              {stick.brand}
  261.            Memory Type:        {stick.mem_type}
  262.            Speed:              {stick.speed}
  263.            Size:               {stick.size}
  264.        """
  265.     )
  266.    
  267. n_drives = []
  268. for n in system.drives.nvme:
  269.     parts = []
  270.     for p in n.paritions:
  271.         parts.append(
  272.             f"""
  273.                Volume:         {p.mount_point}
  274.                Capacity:       {p.capacity}
  275.                Used:           {p.used}
  276.                Free:           {p.free}
  277.                Bitlocker       {p.bitlocker}
  278.            """
  279.         )
  280.     n_drives.append(
  281.         f"""
  282.            Model:              {n.model}
  283.            Serial Number:      {n.sn}
  284.            Capacity:           {n.capacity}
  285.            Volumes:
  286.                {"".join(parts)}
  287.        """
  288.     )
  289.  
  290. s_drives = []
  291. for s in system.drives.sata:
  292.     parts = []
  293.     for p in s.paritions:
  294.         parts.append(
  295.             f"""
  296.                Volume:         {p.mount_point}
  297.                Capacity:       {p.capacity}
  298.                Used:           {p.used}
  299.                Free:           {p.free}
  300.                Bitlocker:      {p.bitlocker}
  301.            """
  302.         )
  303.     s_drives.append(
  304.         f"""
  305.            Model:              {s.model}
  306.            Serial Number:      {s.sn}
  307.            Capacity:           {s.capacity}
  308.            Volumes:
  309.                {"".join(parts)}
  310.        """
  311.     )
  312.  
  313. result = f"""System:
  314.    Name:                       {system.name}
  315.    OS:                         {system.os}
  316.    Brand:                      {system.brand}
  317.    UEFI:                       {system.uefi}
  318.    Secure Boot:                {system.sb}
  319.    
  320.    Motherboard:
  321.        Model:                  {system.mobo.model}
  322.        Chipset:                {system.mobo.chipset}
  323.        USB Version:            {system.mobo.usb_version}
  324.        TPM:                    {system.mobo.tpm}
  325.        
  326.    RAM:
  327.        Total Size:             {system.ram.total}
  328.        Installed Sticks:
  329.            {"".join(ram_sticks)}
  330.    CPU:
  331.        Name:                   {system.cpu.name}
  332.        Cores:                  {system.cpu.cores}
  333.        Logical Cores:          {system.cpu.lcores}
  334.        Clock Speed:            {system.cpu.hz}
  335.    
  336.    GPU:
  337.        Name:                   {system.gpu.name}
  338.        Memory:                 {system.gpu.vram}
  339.        Clock:                  {system.gpu.clock}
  340.        Memory Clock:           {system.gpu.m_clock}
  341.    
  342.    Storage:
  343.        NVMe Drives:
  344.                {"".join(n_drives)}
  345.        SATA Drives:
  346.                {"".join(s_drives)}
  347.    """
  348.  
  349. print(result)
  350. with open("out.txt", "w") as f:
  351.     f.write(result)
  352. input()
Advertisement
Add Comment
Please, Sign In to add comment