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.

63 lines
1.7 KiB

import re
import sys
import os
import requests
import datetime
dt = datetime.datetime.utcnow().strftime("%m-%d-%H")
numberOfHSDir = 0
numberOfNonv2HSDir = 0
numberOfv2HSDir = 0
numberOfNonv2 = 0
numberOfv2 = 0
consensus = "consensus"
url = "https://collector.torproject.org/recent/relay-descriptors/consensuses/2021-{}-00-00-consensus".format(dt)
print(url)
r = requests.get(url)
os.remove(consensus)
with open(consensus,"wb") as output:
output.write(r.content)
#file = open("/var/lib/tor/cached-microdesc-consensus", "r")
file = open(consensus, "r")
while True:
line1 = file.readline()
if not line1: break
if re.search("^s", line1, re.IGNORECASE):
isHSDir = False
if re.search("^s.*HSDir", line1, re.IGNORECASE):
numberOfHSDir += 1
isHSDir = True
line2 = file.readline()
if re.search("^v.*Tor (0.4.[6-9]|0.3.5.17|0.4.5.11)", line2, re.IGNORECASE):
if isHSDir:
numberOfNonv2HSDir += 1
numberOfNonv2 += 1
else:
if isHSDir:
numberOfv2HSDir += 1
numberOfv2 += 1
dt = datetime.datetime.utcnow().strftime("%Y/%m/%d %H")
with open("/home/trackingv2/trackingv2.csv", "a") as csvFile:
csvFile.write("{},{},{},{}\n".format(numberOfv2HSDir, numberOfNonv2HSDir, numberOfHSDir, dt))
with open("trackingv2relays.csv", "a") as relaysCsv:
relaysCsv.write("{},{},{}\n".format(numberOfv2, numberOfNonv2, dt))
#print("Num HSDir: {}".format(numberOfHSDir))
#print("< 0.4.6: {}".format(numberOfv2HSDir))
#print(">= 0.4.6: {}".format(numberOfNonv2HSDir))
#print()
#print("< 0.4.6: {}".format(numberOfv2))
#print(">= 0.4.6: {}".format(numberOfNonv2))
#print("DT: {}".format(dt))