Skip to content

Commit ab41eeb

Browse files
committed
Get Pc information
When running in terminal, can pick a choice to get input devices plugged in, pc inoprmwtion, and network information through this terminal design
1 parent 121ba40 commit ab41eeb

1 file changed

Lines changed: 50 additions & 13 deletions

File tree

My-PC/info.py

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import win32com.client
22
import wmi
3+
import socket
4+
import psutil
5+
6+
7+
# code source: https://thepythoncode.com/article/get-hardware-system-information-python
8+
def bytes_to_human(value, suffix="B"):
9+
if value is None:
10+
return "N/A"
11+
value = float(value)
12+
for unit in ("", "K", "M", "G", "T", "P"):
13+
if abs(value) < 1024:
14+
return f"{value:.2f}{unit}{suffix}"
15+
value /= 1024
16+
return f"{value:.2f}EB"
17+
318

419
def info_pc():
5-
c = wmi.WMI()
20+
c = wmi.WMI()
621
my_system = c.Win32_ComputerSystem()[0]
722

823
print(f"Manufacturer: {my_system.Manufacturer}")
@@ -15,20 +30,17 @@ def info_pc():
1530

1631
def list_plugged_in_devices():
1732
print("Loading getting machine devices\n")
18-
33+
1934
# WMI API
2035
wmi = win32com.client.GetObject("winmgmts:")
2136

2237
# query used to get the device information
23-
devices = wmi.ExecQuery(
24-
"""
38+
devices = wmi.ExecQuery("""
2539
SELECT Name, DeviceID, Manufacturer, PNPClass, Present, ConfigManagerErrorCode
2640
FROM Win32_PnPEntity
2741
WHERE Present = True AND Manufacturer != 'Microsoft'
28-
"""
29-
)
42+
""")
3043

31-
3244
print(f"({len(devices)} devices found: \n")
3345
for dev in list(devices):
3446
print(f"Device Name: {dev.Name}")
@@ -39,28 +51,53 @@ def list_plugged_in_devices():
3951
print("-" * 100)
4052

4153

54+
def network_info():
55+
for name, addresses in psutil.net_if_addrs().items():
56+
print("Interface:", name)
57+
for address in addresses:
58+
if address.family == socket.AF_INET:
59+
print(" IPv4:", address.address)
60+
print(" Netmask:", address.netmask)
61+
elif address.family == socket.AF_INET6:
62+
print(" IPv6:", address.address)
63+
elif hasattr(psutil, "AF_LINK") and address.family == psutil.AF_LINK:
64+
print(" MAC:", address.address)
65+
66+
stats = psutil.net_if_stats()
67+
for name, stat in stats.items():
68+
print(name, "up=" + str(stat.isup), "speed=" + str(stat.speed), "Mbps")
69+
70+
io = psutil.net_io_counters()
71+
print("Bytes sent:", bytes_to_human(io.bytes_sent))
72+
print("Bytes received:", bytes_to_human(io.bytes_recv))
73+
74+
4275
def user_console():
4376
while True:
4477
print("\n See Pc information")
4578
print("1) Standard device information")
4679
print("2) Input devices")
47-
print("3) Quit")
48-
80+
print("3) Network Interface")
81+
print("4) Quit")
82+
4983
try:
50-
option = int(input("What would you like to see about your device? (1-3): "))
51-
84+
option = int(input("What would you like to see about your device? (1-4): "))
85+
5286
if option == 1:
5387
info_pc()
5488
elif option == 2:
5589
list_plugged_in_devices()
5690
elif option == 3:
91+
network_info()
92+
elif option == 4:
5793
print("Exiting console application. Goodbye!")
58-
break
94+
break
5995
else:
6096
print("Invalid choice! Please choose 1, 2, or 3.")
61-
97+
6298
except ValueError:
6399
print("Error: Please enter a valid number (1, 2, or 3).")
64100

101+
65102
if __name__ == "__main__":
66103
user_console()

0 commit comments

Comments
 (0)