Compare commits
2 Commits
69dd4bd1f4
...
1aad27b937
| Author | SHA1 | Date | |
|---|---|---|---|
| 1aad27b937 | |||
| 2521b34df0 |
52
status.py
52
status.py
@@ -5,18 +5,7 @@ import ipaddress
|
|||||||
def read_document(document_name):
|
def read_document(document_name):
|
||||||
with open(document_name, 'r') as file:
|
with open(document_name, 'r') as file:
|
||||||
# Leer todas las líneas del archivo y guardarlas en un conjunto
|
# Leer todas las líneas del archivo y guardarlas en un conjunto
|
||||||
lines = file.readlines()
|
return {linea.rstrip('\n') for linea in file}
|
||||||
ips = set()
|
|
||||||
for line in lines:
|
|
||||||
# Eliminar caracteres de nueva línea y espacios en blanco alrededor
|
|
||||||
line = line.strip()
|
|
||||||
# Convertir la línea a un objeto IPv4Address
|
|
||||||
try:
|
|
||||||
ip = ipaddress.IPv4Address(line)
|
|
||||||
ips.add(ip)
|
|
||||||
except ipaddress.AddressValueError:
|
|
||||||
print(f"La entrada '{line}' no es una dirección IP válida.")
|
|
||||||
return ips
|
|
||||||
|
|
||||||
def parseArguments():
|
def parseArguments():
|
||||||
# Crear un objeto ArgumentParser
|
# Crear un objeto ArgumentParser
|
||||||
@@ -29,10 +18,10 @@ def parseArguments():
|
|||||||
try:
|
try:
|
||||||
# Parsear los argumentos de la línea de comandos
|
# Parsear los argumentos de la línea de comandos
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.web:
|
if args.host:
|
||||||
return args.web
|
|
||||||
elif args.host:
|
|
||||||
return args.host
|
return args.host
|
||||||
|
elif args.web:
|
||||||
|
return args.web
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
# Si ocurre un error al analizar los argumentos, mostrar un mensaje de error
|
# Si ocurre un error al analizar los argumentos, mostrar un mensaje de error
|
||||||
print("Error:", e)
|
print("Error:", e)
|
||||||
@@ -40,15 +29,32 @@ def parseArguments():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def check_ping(host):
|
def toIP(hosts):
|
||||||
try:
|
ips = set()
|
||||||
response = ping(host, count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
for host in hosts:
|
||||||
return True if response.success() else False
|
try:
|
||||||
except Exception as e:
|
ip = ipaddress.IPv4Address(host)
|
||||||
print(f"Error making ping to {host}: {e}")
|
ips.add(ip)
|
||||||
return False
|
except ipaddress.AddressValueError:
|
||||||
|
print(f"La entrada '{ip}' no es una dirección IP válida.")
|
||||||
|
return ips
|
||||||
|
|
||||||
|
def check_ping(hosts):
|
||||||
|
for host in hosts:
|
||||||
|
try:
|
||||||
|
print(f'Pingin host: {host}')
|
||||||
|
response = ping(str(host), count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||||
|
if not response.success():
|
||||||
|
print(False)
|
||||||
|
# Ennviar un mensaje
|
||||||
|
else:
|
||||||
|
print(True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error making ping to {host}: {e}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parseArguments()
|
args = parseArguments()
|
||||||
print(check_ping(args))
|
hosts = read_document(args)
|
||||||
|
ips = toIP(hosts)
|
||||||
|
check_ping(ips)
|
||||||
Reference in New Issue
Block a user