relay_status/relaystatus.py

44 lines
2.1 KiB
Python
Raw Normal View History

2021-09-27 00:20:37 +00:00
import requests
2021-10-28 22:16:50 +00:00
import re
2021-09-27 00:20:37 +00:00
import os
2021-09-27 02:18:20 +00:00
import datetime
2021-09-27 00:20:37 +00:00
import json
2021-09-27 02:18:20 +00:00
import smtplib
2021-09-27 00:20:37 +00:00
url = "https://onionoo.torproject.org/details"
r = requests.get(url)
relays = json.loads(r.content)["relays"]
2021-11-19 12:39:51 +00:00
relayWatchEmail = "From: relay status <relaystatus@encryptionin.space>\nTo: relaywatch@lists.encryptionin.space\nSubject: Relay Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n"
relayStatus = ""
exitWatchEmail = "From: relay status <relaystatus@encryptionin.space>\nTo: exitwatch@lists.encryptionin.space\nSubject: Exit Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n"
exitStatus = ""
2021-09-29 22:29:38 +00:00
for new_relay in relays:
if datetime.datetime.strptime(new_relay["first_seen"], "%Y-%m-%d %H:%M:%S") > (datetime.datetime.utcnow() - datetime.timedelta(hours=1)):
2021-09-29 22:29:38 +00:00
exit = "no"
eol = "no"
2021-12-26 00:37:48 +00:00
if not re.search("0.3.5|0.4.5|0.4.6|0.4.7", new_relay["platform"], re.IGNORECASE):
eol = "yes"
2021-09-29 22:29:38 +00:00
if new_relay["exit_policy"][0] != "reject *:*":
exit = "yes"
2021-12-26 01:54:08 +00:00
exitStatus += "\"" new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", EOL: " + eol + ", effective family: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n"
relayStatus += new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", exit: " + exit + ", EOL: " + eol + ", effective family: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n"
2021-09-29 22:29:38 +00:00
2021-11-19 12:39:51 +00:00
if relayStatus:
relayWatchEmail += relayStatus
2021-11-19 12:39:51 +00:00
try:
smtp = smtplib.SMTP('localhost')
smtp.sendmail('relaystatus@encryptionin.space', ['relaywatch@lists.encryptionin.space'], relayWatchEmail)
except:
print("couldn't send")
if exitStatus:
exitWatchEmail += exitStatus
2021-09-29 22:29:38 +00:00
try:
smtp = smtplib.SMTP('localhost')
2021-11-19 12:39:51 +00:00
smtp.sendmail('relaystatus@encryptionin.space', ['exitwatch@lists.encryptionin.space'], exitWatchEmail)
2021-09-30 16:17:33 +00:00
except:
2021-09-29 22:29:38 +00:00
print("couldn't send")