Add exit watch

This commit is contained in:
HackerNCoder 2021-11-19 12:39:51 +00:00
parent 487f531a8c
commit d518805770

View file

@ -9,8 +9,11 @@ url = "https://onionoo.torproject.org/details"
r = requests.get(url) r = requests.get(url)
relays = json.loads(r.content)["relays"] relays = json.loads(r.content)["relays"]
email = "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" 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"
status = "" 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 newVersions = 0
@ -19,15 +22,24 @@ for new_relay in relays:
exit = "no" exit = "no"
if new_relay["exit_policy"][0] != "reject *:*": if new_relay["exit_policy"][0] != "reject *:*":
exit = "yes" exit = "yes"
status += "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" 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): if re.search("0.3.5.17|0.4.5.11", new_relay["platform"], re.IGNORECASE):
newVersions += 1 newVersions += 1
if status: if relayStatus:
email += status + "\nTotal new versions: " + str(newVersions) + "\n" relayWatchEmail += relayStatus + "\nTotal new versions: " + str(newVersions) + "\n"
try: try:
smtp = smtplib.SMTP('localhost') smtp = smtplib.SMTP('localhost')
smtp.sendmail('relaystatus@encryptionin.space', ['relaywatch@lists.encryptionin.space'], email) 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: except:
print("couldn't send") print("couldn't send")