Compare commits
2 Commits
1aad27b937
...
ReadIPs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
807517be96 | ||
| 166067972e |
1
.env
Normal file
1
.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DISCORD_WEBHOOK_URL='https://discord.com/api/webhooks/1229025346385608824/kIt2dp2znu0jR85QbOPmoMAteHaB9BCJDTMfn0cHE9mwpxHkbUNc9By2Y7n6gpufoyco'
|
||||||
39
status.py
39
status.py
@@ -1,6 +1,11 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from pythonping import ping
|
from pythonping import ping
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
def read_document(document_name):
|
def read_document(document_name):
|
||||||
with open(document_name, 'r') as file:
|
with open(document_name, 'r') as file:
|
||||||
@@ -17,11 +22,7 @@ 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()
|
return parser.parse_args()
|
||||||
if 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)
|
||||||
@@ -36,7 +37,7 @@ def toIP(hosts):
|
|||||||
ip = ipaddress.IPv4Address(host)
|
ip = ipaddress.IPv4Address(host)
|
||||||
ips.add(ip)
|
ips.add(ip)
|
||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
print(f"La entrada '{ip}' no es una dirección IP válida.")
|
print(f"La entrada '{host}' no es una dirección IP válida.")
|
||||||
return ips
|
return ips
|
||||||
|
|
||||||
def check_ping(hosts):
|
def check_ping(hosts):
|
||||||
@@ -46,15 +47,33 @@ def check_ping(hosts):
|
|||||||
response = ping(str(host), count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
response = ping(str(host), count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||||
if not response.success():
|
if not response.success():
|
||||||
print(False)
|
print(False)
|
||||||
# Ennviar un mensaje
|
send_discord_message(f"Ping fallido para el host: {host}")
|
||||||
else:
|
else:
|
||||||
print(True)
|
print(True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error making ping to {host}: {e}")
|
print(f"Error making ping to {host}: {e}")
|
||||||
|
|
||||||
|
def send_discord_message(message):
|
||||||
|
webhook_url = os.getenv('DISCORD_WEBHOOK_URL')
|
||||||
|
data = {
|
||||||
|
"content": message
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
response = requests.post(webhook_url, json=data)
|
||||||
|
response.raise_for_status()
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Error sending Discord message: {e}")
|
||||||
|
else:
|
||||||
|
print("Discord message sent successfully!")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parseArguments()
|
args = parseArguments()
|
||||||
hosts = read_document(args)
|
ips_and_hosts = set()
|
||||||
ips = toIP(hosts)
|
if args.host:
|
||||||
check_ping(ips)
|
ips_and_hosts.update(toIP(read_document(args.host)))
|
||||||
|
print(ips_and_hosts)
|
||||||
|
if args.web:
|
||||||
|
print("Hay webs")
|
||||||
|
# Parsear correctamente
|
||||||
|
# ips_and_hosts.update()
|
||||||
|
check_ping(ips_and_hosts)
|
||||||
Reference in New Issue
Block a user