Skip to content
Open

My pc #102

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions My-PC/MyWebsite
Submodule MyWebsite added at 2fe5f4
Empty file added My-PC/README.md
Empty file.
103 changes: 103 additions & 0 deletions My-PC/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import win32com.client
import wmi
import socket
import psutil


# code source: https://thepythoncode.com/article/get-hardware-system-information-python
def bytes_to_human(value, suffix="B"):
if value is None:
return "N/A"
value = float(value)
for unit in ("", "K", "M", "G", "T", "P"):
if abs(value) < 1024:
return f"{value:.2f}{unit}{suffix}"
value /= 1024
return f"{value:.2f}EB"


def info_pc():
c = wmi.WMI()
my_system = c.Win32_ComputerSystem()[0]

print(f"Manufacturer: {my_system.Manufacturer}")
print(f"Model: {my_system. Model}")
print(f"Name: {my_system.Name}")
print(f"NumberOfProcessors: {my_system.NumberOfProcessors}")
print(f"SystemType: {my_system.SystemType}")
print(f"SystemFamily: {my_system.SystemFamily}")


def list_plugged_in_devices():
print("Loading getting machine devices\n")

# WMI API
wmi = win32com.client.GetObject("winmgmts:")

# query used to get the device information
devices = wmi.ExecQuery("""
SELECT Name, DeviceID, Manufacturer, PNPClass, Present, ConfigManagerErrorCode
FROM Win32_PnPEntity
WHERE Present = True AND Manufacturer != 'Microsoft'
""")

print(f"({len(devices)} devices found: \n")
for dev in list(devices):
print(f"Device Name: {dev.Name}")
print(f" * Manufacturer: {dev.Manufacturer}")
print(f" * Class type: {dev.PNPClass}")
print(f" * Device ID: {dev.DeviceID}")
print(f" * Status Code: {dev.ConfigManagerErrorCode} (0 = Working Perfect)")
print("-" * 100)


def network_info():
for name, addresses in psutil.net_if_addrs().items():
print("Interface:", name)
for address in addresses:
if address.family == socket.AF_INET:
print(" IPv4:", address.address)
print(" Netmask:", address.netmask)
elif address.family == socket.AF_INET6:
print(" IPv6:", address.address)
elif hasattr(psutil, "AF_LINK") and address.family == psutil.AF_LINK:
print(" MAC:", address.address)

stats = psutil.net_if_stats()
for name, stat in stats.items():
print(name, "up=" + str(stat.isup), "speed=" + str(stat.speed), "Mbps")

io = psutil.net_io_counters()
print("Bytes sent:", bytes_to_human(io.bytes_sent))
print("Bytes received:", bytes_to_human(io.bytes_recv))


def user_console():
while True:
print("\n See Pc information")
print("1) Standard device information")
print("2) Input devices")
print("3) Network Interface")
print("4) Quit")

try:
option = int(input("What would you like to see about your device? (1-4): "))

if option == 1:
info_pc()
elif option == 2:
list_plugged_in_devices()
elif option == 3:
network_info()
elif option == 4:
print("Exiting console application. Goodbye!")
break
else:
print("Invalid choice! Please choose 1, 2, or 3.")

except ValueError:
print("Error: Please enter a valid number (1, 2, or 3).")


if __name__ == "__main__":
user_console()
Binary file added My-PC/requirements.txt
Binary file not shown.