ReadIPs #1
1
.env
Normal file
1
.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DISCORD_WEBHOOK_URL='https://discord.com/api/webhooks/1229025346385608824/kIt2dp2znu0jR85QbOPmoMAteHaB9BCJDTMfn0cHE9mwpxHkbUNc9By2Y7n6gpufoyco'
|
||||||
19
status.py
19
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:
|
||||||
@@ -42,12 +47,24 @@ 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user