Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import psutil
|
2 |
+
import socket
|
3 |
+
|
4 |
+
def get_ip_addresses():
|
5 |
+
ip_addresses = []
|
6 |
+
# Get all network interfaces
|
7 |
+
interfaces = psutil.net_if_addrs()
|
8 |
+
for interface_name, interface_addresses in interfaces.items():
|
9 |
+
for address in interface_addresses:
|
10 |
+
# Filter out loopback and link-local addresses
|
11 |
+
if address.family == socket.AF_INET and not address.address.startswith('127.') and not address.address.startswith('169.254.'):
|
12 |
+
ip_addresses.append((interface_name, address.address))
|
13 |
+
return ip_addresses
|
14 |
+
|
15 |
+
def get_system_info():
|
16 |
+
system_info = {}
|
17 |
+
# Get the hostname
|
18 |
+
system_info['Hostname'] = socket.gethostname()
|
19 |
+
# Get the IP addresses
|
20 |
+
system_info['IP Addresses'] = get_ip_addresses()
|
21 |
+
# Get CPU info
|
22 |
+
system_info['CPU'] = f"{psutil.cpu_count()} cores"
|
23 |
+
# Get RAM info
|
24 |
+
mem_info = psutil.virtual_memory()
|
25 |
+
system_info['RAM'] = f"{mem_info.total / (1024 ** 3):.2f} GB"
|
26 |
+
# Get disk usage info
|
27 |
+
disk_info = psutil.disk_usage('/')
|
28 |
+
system_info['Disk Usage'] = f"{disk_info.used / (1024 ** 3):.2f} GB / {disk_info.total / (1024 ** 3):.2f} GB"
|
29 |
+
return system_info
|
30 |
+
|
31 |
+
def print_system_info():
|
32 |
+
system_info = get_system_info()
|
33 |
+
print("System Information:")
|
34 |
+
for key, value in system_info.items():
|
35 |
+
if isinstance(value, list):
|
36 |
+
print(f"{key}:")
|
37 |
+
for item in value:
|
38 |
+
print(f" {item[0]}: {item[1]}")
|
39 |
+
else:
|
40 |
+
print(f"{key}: {value}")
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
print_system_info()
|