-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_info_console.py
132 lines (115 loc) · 5.57 KB
/
system_info_console.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import Pmw
import platform
import threading
import psutil
from datetime import datetime
ventana = Pmw.initialise(fontScheme = 'pmw1')
ventana.title("SYSTEM/HARDWARE INFO")
def get_size(bytes, suffix="B"):
factor = 1024
for unit in ["", "K", "M", "G", "T", "P"]:
if bytes < factor:
return f"{bytes:.2f}{unit}{suffix}"
bytes /= factor
def clear():
display.clear()
display.appendtext("USE THE BUTTONS TO SELECT THE INFORMATION.\n\n")
def network():
display.appendtext(("="*45)+"Network Information"+(("=")*45)+"\n")
if_addrs = psutil.net_if_addrs()
for interface_name, interface_addresses in if_addrs.items():
for address in interface_addresses:
display.appendtext(f"=== Interface: {interface_name} ===\n")
if str(address.family) == 'AddressFamily.AF_INET':
display.appendtext(f" IP Address: {address.address}\n")
display.appendtext(f" Netmask: {address.netmask}\n")
display.appendtext(f" Broadcast IP: {address.broadcast}\n")
elif str(address.family) == 'AddressFamily.AF_PACKET':
display.appendtext(f" MAC Address: {address.address}\n")
display.appendtext(f" Netmask: {address.netmask}\n")
display.appendtext(f" Broadcast MAC: {address.broadcast}\n")
net_io = psutil.net_io_counters()
display.appendtext(f"Total Bytes Sent: {get_size(net_io.bytes_sent)}\n")
display.appendtext(f"Total Bytes Received: {get_size(net_io.bytes_recv)}\n")
def disk():
display.appendtext(("="*46)+"Disk Information"+(("=")*46)+"\n")
display.appendtext("Partitions and Usage:\n")
partitions = psutil.disk_partitions()
for partition in partitions:
display.appendtext(f"=== Device: {partition.device} ===\n")
display.appendtext(f" Mountpoint: {partition.mountpoint}\n")
display.appendtext(f" File system type: {partition.fstype}\n")
try:
partition_usage = psutil.disk_usage(partition.mountpoint)
except PermissionError:
continue
display.appendtext(f" Total Size: {get_size(partition_usage.total)}\n")
display.appendtext(f" Used: {get_size(partition_usage.used)}\n")
display.appendtext(f" Free: {get_size(partition_usage.free)}\n")
display.appendtext(f" Percentage: {partition_usage.percent}%\n")
disk_io = psutil.disk_io_counters()
display.appendtext(f" Total read: {get_size(disk_io.read_bytes)}\n")
display.appendtext(f" Total write: {get_size(disk_io.write_bytes)}\n")
def memory():
display.appendtext(("="*45)+"Memory Information"+(("=")*45)+"\n")
svmem = psutil.virtual_memory()
display.appendtext(f"Total: {get_size(svmem.total)}\n")
display.appendtext(f"Available: {get_size(svmem.available)}\n")
display.appendtext(f"Used: {get_size(svmem.used)}\n")
display.appendtext(f"Percentage: {svmem.percent}%\n")
display.appendtext(("="*20)+"SWAP"+("="*20)+"\n")
swap = psutil.swap_memory()
display.appendtext(f"Total: {get_size(swap.total)}\n")
display.appendtext(f"Free: {get_size(swap.free)}\n")
display.appendtext(f"Used: {get_size(swap.used)}\n")
display.appendtext(f"Percentage: {swap.percent}%\n")
def system():
display.appendtext(("="*45)+"System Information"+(("=")*45)+"\n")
uname = platform.uname()
display.appendtext(f"System: {uname.system}\n")
display.appendtext(f"Node Name: {uname.node}\n")
display.appendtext(f"Release: {uname.release}\n")
display.appendtext(f"Version: {uname.version}\n")
display.appendtext(f"Machine: {uname.machine}\n")
display.appendtext(f"Processor: {uname.processor}\n")
def cpu():
display.appendtext(("="*47)+"CPU Information"+(("=")*47)+"\n")
display.appendtext(("Physical cores: "+str(psutil.cpu_count(logical=False))))
display.appendtext("\n")
display.appendtext(("Total cores: "+str(psutil.cpu_count(logical=True))))
display.appendtext("\n")
cpufreq = psutil.cpu_freq()
display.appendtext(f"Max Frequency: {cpufreq.max:.2f}Mhz\n")
display.appendtext(f"Min Frequency: {cpufreq.min:.2f}Mhz\n")
display.appendtext(f"Current Frequency: {cpufreq.current:.2f}Mhz\n")
display.appendtext("CPU Usage Per Core:\n")
for i, percentage in enumerate(psutil.cpu_percent(percpu=True)):
display.appendtext(f"Core {i}: {percentage}%\n")
display.appendtext(f"Total CPU Usage: {psutil.cpu_percent()}%\n")
def inicia(index):
infos={0:system,1:cpu,2:memory,3:disk,4:network}
t=threading.Thread(target=infos[index])
t.start()
#PANTALLA
display = Pmw.ScrolledText(ventana, hscrollmode='none',
vscrollmode='dynamic', hull_relief='sunken',
hull_background='gray20', hull_borderwidth=10,
text_background='black', text_width=109,
text_foreground='green', text_height=39,
text_padx=10, text_pady=10, text_relief='groove',
text_font=('Fixedsys', 10))
display.pack(padx=0,pady=0)
#BOTONES
botones = Pmw.ButtonBox(ventana)
botones.pack(fill='both', expand=1, padx=1, pady=1)
botones.add('System Info',command=lambda:inicia(0),width=15,bg='light green')
botones.add('CPU Info',command=lambda:inicia(1),bg='light green')
botones.add('Memory Info',command=lambda:inicia(2),bg='light green')
botones.add('Disk Info',command=lambda:inicia(3),bg='light green')
botones.add('Network Info',command=lambda:inicia(4),bg='light green')
botones.add('CLEAR',command=clear,bg='light blue')
botones.alignbuttons()
clear()
ventana.mainloop()