Files
Status/status.py

39 lines
1.3 KiB
Python

import argparse
from pythonping import ping
import sys
def parseArguments():
# Crear un objeto ArgumentParser
parser = argparse.ArgumentParser(description='Ejemplo de script con flags')
# Agregar los argumentos con sus respectivos flags
parser.add_argument('-W', '--web', action='store', dest='web', help='Indicar un archivo con lista de Webs')
parser.add_argument('-H', '--host', action='store', dest='host', help='Indicar un archivo con lista de hosts')
try:
# Parsear los argumentos de la línea de comandos
args = parser.parse_args()
if args.web:
return args.web
elif args.host:
return args.host
except argparse.ArgumentError as e:
# Si ocurre un error al analizar los argumentos, mostrar un mensaje de error
print("Error:", e)
# Mostrar el mensaje de ayuda
parser.print_help()
exit()
def check_ping(host):
try:
response = ping(host, count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
return True if response.success() else False
except Exception as e:
print(f"Error making ping to {host}: {e}")
return False
if __name__ == '__main__':
args = parseArguments()
print(check_ping(args))