@ -1,10 +1,47 @@
import os
import platform
import socket
import subprocess
import psutil
import psutil
import matplotlib . pyplot as plt
threads_por_nucleo = psutil . cpu_count ( logical = False )
threads_por_nucleo = psutil . cpu_count ( logical = False )
memoria = psutil . virtual_memory ( )
memoria = psutil . virtual_memory ( )
def display_horizontal_bar ( label , value , max_value = 100 , bar_length = 20 , color = ' \033 [0m ' ) :
percentage = ( value / max_value ) * 100
bar_fill_length = int ( bar_length * ( percentage / 100 ) )
bar = f " { color } | " + ' = ' * bar_fill_length + ' ' * ( bar_length - bar_fill_length ) + f ' { color } | '
print ( f " { label } { bar } { percentage : .2f } % \033 [0m " )
def get_process_states ( ) :
# Get a list of all running processes
processes = psutil . process_iter ( [ ' pid ' , ' name ' , ' status ' ] )
# Initialize counters for different process states
running_count = 0
sleeping_count = 0
other_count = 0
# Iterate through processes and count their states
for process in processes :
status = process . info [ ' status ' ] . lower ( )
if ' running ' in status :
running_count + = 1
elif ' sleeping ' in status :
sleeping_count + = 1
else :
other_count + = 1
return running_count , sleeping_count , other_count
def get_running_processes ( ) :
def get_running_processes ( ) :
# Using list comprehension to get information about all running processes
# Using list comprehension to get information about all running processes
return [ proc . info for proc in psutil . process_iter ( [ ' pid ' , ' name ' , ' username ' ] ) ]
return [ proc . info for proc in psutil . process_iter ( [ ' pid ' , ' name ' , ' username ' ] ) ]
def get_tcp_connections ( ) :
connections = psutil . net_connections ( kind = ' inet ' )
return connections
def procesesRunning ( ) :
def procesesRunning ( ) :
# Get and print information about all running processes
# Get and print information about all running processes
@ -22,32 +59,79 @@ ans=True
while ans :
while ans :
print ( """
print ( """
1. Hilos por nucleo
1. Hilos por nucleo
2. Memoria Total
2. Memoria Total , Memoria Diponible y Porcentaje de memoria utilizada
3. M emoria Diponible
3. M odulo OS
4. Porcentaje de memoria utilizad a
4. Informacion sobre drives en el sistem a
5. El estado de bateria
5. El estado de bateria
6. Procesos activados
6. Procesos activados
7. El uso del CPU
7. El uso del CPU , memoria y swap
8. Exit / Quit
8. Lista de connecciones TPC
9. Temperatura
10. Socket info
11. Modulo de plataforma
12. Numero de precesos activos , dormidos y otros
0. Salir
""" )
""" )
ans = input ( " Elige que tipo de informacio deseas saber: " )
ans = input ( " Elige que tipo de informacio deseas saber: " )
if ans == " 1 " :
if ans == " 1 " :
print ( f " Tu procesador tiene { threads_por_nucleo } hilos por núcleo. " )
print ( f " Tu procesador tiene { threads_por_nucleo } hilos por núcleo. " )
elif ans == " 2 " :
elif ans == " 2 " :
print ( f " Memoria total: { memoria . total } bytes " )
print ( f " Memoria total: { memoria . total } bytes " )
print ( f " Memoria disponible: { memoria . available } bytes " )
print ( f " Porcentaje de memoria utilizada: { memoria . percent } % " )
elif ans == " 3 " :
elif ans == " 3 " :
print ( f " Memoria disponible: { memoria . available } bytes " )
cpu_count = os . cpu_count ( )
print ( f " CPU Count: { cpu_count } " )
current_directory = os . getcwd ( )
print ( f " Current Directory: { current_directory } " )
elif ans == " 4 " :
elif ans == " 4 " :
print ( f " Porcentaje de memoria utilizada: { memoria . percent } % " )
result = subprocess . run ( [ ' powershell ' , ' Get-PSDrive ' ] , stdout = subprocess . PIPE , text = True )
print ( result . stdout )
elif ans == " 5 " :
elif ans == " 5 " :
print ( percent + ' % | ' + plugged )
print ( percent + ' % | ' + plugged )
elif ans == " 6 " :
elif ans == " 6 " :
procesesRunning ( )
procesesRunning ( )
elif ans == " 7 " :
elif ans == " 7 " :
cpu_usage = psutil . cpu_percent ( interval = 1 )
cpu_usage = psutil . cpu_percent ( interval = 1 )
print ( f " CPU Usage: { cpu_usage } % " )
memory_info = psutil . virtual_memory ( )
elif ans == " 8 " :
swap_info = psutil . swap_memory ( )
print ( " \n Goodbye " )
display_horizontal_bar ( ' CPU ' , cpu_usage , color = ' \033 [91m ' )
ans = None
display_horizontal_bar ( ' Memoria ' , memory_info . percent , color = ' \033 [94m ' )
display_horizontal_bar ( ' Swap ' , swap_info . percent , color = ' \033 [92m ' )
elif ans == " 8 " :
if __name__ == " __main__ " :
tcp_connections = get_tcp_connections ( )
for connection in tcp_connections :
print ( f " Local Address: { connection . laddr } " )
print ( f " Remote Address: { connection . raddr } " )
print ( f " Status: { connection . status } " )
print ( " ----------------------------------- " )
elif ans == " 9 " :
try :
temperatures = psutil . sensors_temperatures ( )
print ( " Temperatura: " )
for name , entries in temperatures . items ( ) :
for entry in entries :
print ( f " { name } : { entry . label } - { entry . current } °C " )
except AttributeError :
print ( " la informacion sobre temeratura no esta disponible ens ete sitema " )
elif ans == " 10 " :
hostname = socket . gethostname ( )
ip_address = socket . gethostbyname ( hostname )
print ( f " Hostname: { hostname } " )
print ( f " IP Address: { ip_address } " )
elif ans == " 11 " :
system_info = platform . system ( )
release_info = platform . release ( )
print ( f " System: { system_info } " )
print ( f " Release: { release_info } " )
elif ans == " 12 " :
running , sleeping , other = get_process_states ( )
print ( f " Processos activos: { running } " )
print ( f " procesos dormiendo: { sleeping } " )
print ( f " Otros procesos: { other } " )
elif ans == " 0 " :
print ( " \n Adios " )
ans = None
else :
else :
print ( " \n Not Valid Choice Try again " )
print ( " \n no es una pocion valida " )