statusFeature #2
20
status.py
20
status.py
@@ -40,17 +40,31 @@ def toIP(hosts):
|
||||
print(f"La entrada '{host}' no es una dirección IP válida.")
|
||||
return ips
|
||||
|
||||
def check_ping(hosts):
|
||||
def check_ping(hosts, fails):
|
||||
for host in hosts:
|
||||
try:
|
||||
response = ping(str(host), count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||
if not response.success():
|
||||
logging.info(f"Bad ping: {host}")
|
||||
if (host not in fails):
|
||||
send_discord_message(f"Ping fallido para el host: {host}")
|
||||
# Añadir el host a fails
|
||||
fails.add(host)
|
||||
elif response.success():
|
||||
if host in fails:
|
||||
fails.remove(host)
|
||||
logging.info(f"Ping correct: {host}")
|
||||
except Exception as e:
|
||||
logging.info(f"Bad ping: {host}")
|
||||
print(e)
|
||||
print(fails)
|
||||
save_status(fails)
|
||||
|
||||
def save_status(fails):
|
||||
with open("failed.txt", "w") as file:
|
||||
for fail in fails:
|
||||
file.write(str(fail) + "\n")
|
||||
file.close
|
||||
|
||||
def send_discord_message(message):
|
||||
data = {
|
||||
@@ -68,10 +82,12 @@ def send_discord_message(message):
|
||||
if __name__ == '__main__':
|
||||
args = parseArguments()
|
||||
ips_and_hosts = set()
|
||||
fails = set()
|
||||
if args.host:
|
||||
ips_and_hosts.update(toIP(read_document(args.host)))
|
||||
fails.update(toIP(read_document("failed.txt")))
|
||||
if args.web:
|
||||
print("Hay webs")
|
||||
# Parsear correctamente
|
||||
# ips_and_hosts.update()
|
||||
check_ping(ips_and_hosts)
|
||||
check_ping(ips_and_hosts, fails)
|
||||
Reference in New Issue
Block a user