Compare commits
6 Commits
ReadIPs
...
aad6fb97a6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aad6fb97a6 | ||
|
|
6ab6224ff6 | ||
|
|
2b986eeabb | ||
|
|
90a7cb8581 | ||
|
|
7bccab9455 | ||
| 03b7177ecf |
22
status.py
22
status.py
@@ -2,10 +2,10 @@ import argparse
|
|||||||
from pythonping import ping
|
from pythonping import ping
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import requests
|
import requests
|
||||||
import os
|
import logging
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
load_dotenv()
|
DISCORD_WEBHOOK_URL='https://discord.com/api/webhooks/1229025346385608824/kIt2dp2znu0jR85QbOPmoMAteHaB9BCJDTMfn0cHE9mwpxHkbUNc9By2Y7n6gpufoyco'
|
||||||
|
logging.basicConfig(filename='/var/log/status.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
def read_document(document_name):
|
def read_document(document_name):
|
||||||
with open(document_name, 'r') as file:
|
with open(document_name, 'r') as file:
|
||||||
@@ -43,35 +43,33 @@ def toIP(hosts):
|
|||||||
def check_ping(hosts):
|
def check_ping(hosts):
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
try:
|
try:
|
||||||
print(f'Pingin host: {host}')
|
|
||||||
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)
|
logging.info(f"Bad ping: {host}")
|
||||||
send_discord_message(f"Ping fallido para el host: {host}")
|
send_discord_message(f"Ping fallido para el host: {host}")
|
||||||
else:
|
elif response.success():
|
||||||
print(True)
|
logging.info(f"Ping correct: {host}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error making ping to {host}: {e}")
|
logging.info(f"Bad ping: {host}")
|
||||||
|
|
||||||
def send_discord_message(message):
|
def send_discord_message(message):
|
||||||
webhook_url = os.getenv('DISCORD_WEBHOOK_URL')
|
|
||||||
data = {
|
data = {
|
||||||
"content": message
|
"content": message
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
response = requests.post(webhook_url, json=data)
|
response = requests.post(DISCORD_WEBHOOK_URL, json=data)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Error sending Discord message: {e}")
|
print(f"Error sending Discord message: {e}")
|
||||||
|
logging.info(f"Error sending Discord message: {e}")
|
||||||
else:
|
else:
|
||||||
print("Discord message sent successfully!")
|
logging.info("Discord message sent successfully!")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parseArguments()
|
args = parseArguments()
|
||||||
ips_and_hosts = set()
|
ips_and_hosts = set()
|
||||||
if args.host:
|
if args.host:
|
||||||
ips_and_hosts.update(toIP(read_document(args.host)))
|
ips_and_hosts.update(toIP(read_document(args.host)))
|
||||||
print(ips_and_hosts)
|
|
||||||
if args.web:
|
if args.web:
|
||||||
print("Hay webs")
|
print("Hay webs")
|
||||||
# Parsear correctamente
|
# Parsear correctamente
|
||||||
|
|||||||
Reference in New Issue
Block a user