Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,41 @@
|
|
|
|
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 |
-
|
|
|
32 |
system_info = get_system_info()
|
33 |
-
|
34 |
for key, value in system_info.items():
|
35 |
if isinstance(value, list):
|
36 |
-
|
37 |
for item in value:
|
38 |
-
|
39 |
else:
|
40 |
-
|
|
|
41 |
|
42 |
-
if __name__ ==
|
43 |
-
|
|
|
1 |
+
from flask import Flask
|
2 |
import psutil
|
3 |
import socket
|
4 |
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
def get_ip_addresses():
|
8 |
ip_addresses = []
|
|
|
9 |
interfaces = psutil.net_if_addrs()
|
10 |
for interface_name, interface_addresses in interfaces.items():
|
11 |
for address in interface_addresses:
|
|
|
12 |
if address.family == socket.AF_INET and not address.address.startswith('127.') and not address.address.startswith('169.254.'):
|
13 |
ip_addresses.append((interface_name, address.address))
|
14 |
return ip_addresses
|
15 |
|
16 |
def get_system_info():
|
17 |
system_info = {}
|
|
|
18 |
system_info['Hostname'] = socket.gethostname()
|
|
|
19 |
system_info['IP Addresses'] = get_ip_addresses()
|
|
|
20 |
system_info['CPU'] = f"{psutil.cpu_count()} cores"
|
|
|
21 |
mem_info = psutil.virtual_memory()
|
22 |
system_info['RAM'] = f"{mem_info.total / (1024 ** 3):.2f} GB"
|
|
|
23 |
disk_info = psutil.disk_usage('/')
|
24 |
system_info['Disk Usage'] = f"{disk_info.used / (1024 ** 3):.2f} GB / {disk_info.total / (1024 ** 3):.2f} GB"
|
25 |
return system_info
|
26 |
|
27 |
+
@app.route('/')
|
28 |
+
def index():
|
29 |
system_info = get_system_info()
|
30 |
+
output = "System Information:\n"
|
31 |
for key, value in system_info.items():
|
32 |
if isinstance(value, list):
|
33 |
+
output += f"{key}:\n"
|
34 |
for item in value:
|
35 |
+
output += f" {item[0]}: {item[1]}\n"
|
36 |
else:
|
37 |
+
output += f"{key}: {value}\n"
|
38 |
+
return output
|
39 |
|
40 |
+
if __name__ == '__main__':
|
41 |
+
app.run(host='0.0.0.0', port=7860)
|