Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- # Lista de hosts que deseas verificar
- hosts = ["google.com", "example.com", "invalidhost", "localhost"]
- while hosts:
- host = hosts.pop(0) # Obtรฉn y elimina el primer host de la lista
- print(f"Probando la disponibilidad de {host}...")
- # Ejecutar el comando ping y redirigir la salida estรกndar y de error
- try:
- result = subprocess.run(["ping", "-c", "3", host], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
- if "0% packet loss" in result.stdout:
- print(f"{host} estรก disponible.")
- else:
- print(f"{host} no estรก disponible.")
- except subprocess.CalledProcessError:
- print(f"No se pudo realizar el ping a {host}.")
- continue
- print("Escaneo de disponibilidad completo.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement