Advertisement
Sergio_Istea

host_status.py

Oct 23rd, 2023
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import subprocess
  2.  
  3. # Lista de hosts que deseas verificar
  4. hosts = ["google.com", "example.com", "invalidhost", "localhost"]
  5.  
  6. while hosts:
  7.     host = hosts.pop(0)  # Obtรฉn y elimina el primer host de la lista
  8.  
  9.     print(f"Probando la disponibilidad de {host}...")
  10.  
  11.     # Ejecutar el comando ping y redirigir la salida estรกndar y de error
  12.     try:
  13.         result = subprocess.run(["ping", "-c", "3", host], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
  14.  
  15.         if "0% packet loss" in result.stdout:
  16.             print(f"{host} estรก disponible.")
  17.         else:
  18.             print(f"{host} no estรก disponible.")
  19.     except subprocess.CalledProcessError:
  20.         print(f"No se pudo realizar el ping a {host}.")
  21.         continue
  22.  
  23. print("Escaneo de disponibilidad completo.")
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement