You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
2.1 KiB

import requests
import re
import os
import datetime
import json
import smtplib
url = "https://onionoo.torproject.org/details"
r = requests.get(url)
relays = json.loads(r.content)["relays"]
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 = ""
newVersions = 0
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)):
exit = "no"
if new_relay["exit_policy"][0] != "reject *:*":
exit = "yes"
exitStatus += "New exit: \"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", effective family size: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n"
relayStatus += "New relay: \"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", potential exit: " + exit + ", effective family size: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n"
if re.search("0.3.5.17|0.4.5.11", new_relay["platform"], re.IGNORECASE):
newVersions += 1
if relayStatus:
relayWatchEmail += relayStatus + "\nTotal new versions: " + str(newVersions) + "\n"
try:
smtp = smtplib.SMTP('localhost')
smtp.sendmail('relaystatus@encryptionin.space', ['relaywatch@lists.encryptionin.space'], relayWatchEmail)
except:
print("couldn't send")
if exitStatus:
exitWatchEmail += exitStatus
try:
smtp = smtplib.SMTP('localhost')
smtp.sendmail('relaystatus@encryptionin.space', ['exitwatch@lists.encryptionin.space'], exitWatchEmail)
except:
print("couldn't send")