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.
 
trackingv2/trackingv2.py

47 lines
1.2 KiB

import re
import sys
import os
import requests
import datetime
dt = datetime.datetime.utcnow().strftime("%m-%d-%H")
numberOfHSDir = 0
numberOfNonv2 = 0
numberOfv2 = 0
consensus = "/home/trackingv2/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.*HSDir", line1, re.IGNORECASE):
line2 = file.readline()
numberOfHSDir += 1
if re.search("^v.*Tor 0.4.[6-9]", line2, re.IGNORECASE):
numberOfNonv2 += 1
else:
numberOfv2 += 1
dt = datetime.datetime.utcnow().strftime("%Y/%m/%d %H")
with open("/home/trackingv2/trackingv2.csv", "a") as csvFile:
csvFile.write("{},{},{},{}\n".format(numberOfv2, numberOfNonv2, numberOfHSDir, dt))
#print("Num HSDir: {}".format(numberOfHSDir))
#print("< 0.4.6: {}".format(numberOfv2))
#print(">= 0.4.6: {}".format(numberOfNonv2))
#print("DT: {}".format(dt))