trackingv2/trackingv2.py

69 lines
1.9 KiB
Python
Raw Normal View History

2021-08-19 16:24:38 +00:00
import re
import sys
import os
import requests
import datetime
dt = datetime.datetime.utcnow().strftime("%m-%d-%H")
numberOfHSDir = 0
numberOfNonv2HSDir = 0
numberOfv2HSDir = 0
2021-08-19 16:24:38 +00:00
numberOfNonv2 = 0
numberOfv2 = 0
consensus = "consensus"
2021-08-19 16:24:38 +00:00
#url = "https://collector.torproject.org/recent/relay-descriptors/consensuses/2022-{}-00-00-consensus".format(dt)
#print(url)
2021-08-19 16:24:38 +00:00
#r = requests.get(url)
#os.remove(consensus)
#with open(consensus,"wb") as output:
# output.write(r.content)
2021-08-19 16:24:38 +00:00
consensus = open(consensus, "r")
2021-08-19 16:24:38 +00:00
for _ in range(46):
next(consensus)
2021-08-19 16:24:38 +00:00
while True:
line1 = consensus.readline()
2021-08-19 16:24:38 +00:00
if not line1: break
if re.search("^s.*Running", line1, re.IGNORECASE):
isHSDir = False
if re.search("^s.*HSDir", line1, re.IGNORECASE):
numberOfHSDir += 1
isHSDir = True
line2 = consensus.readline()
if re.search("^v Tor 0\.(4\.[6-9]|3\.5\.(17|18)|4\.5\.(11|12|13|14))", line2, re.IGNORECASE):
2022-09-23 20:42:46 +00:00
#print(line1 + " " + line2 + " non")
if isHSDir:
numberOfNonv2HSDir += 1
2021-08-19 16:24:38 +00:00
numberOfNonv2 += 1
else:
2022-09-23 20:42:46 +00:00
#print(line1 + " " + line2 + " v2")
if isHSDir:
numberOfv2HSDir += 1
2021-08-19 16:24:38 +00:00
numberOfv2 += 1
for _ in range(3):
next(consensus)
2021-08-19 16:24:38 +00:00
dt = datetime.datetime.utcnow().strftime("%Y/%m/%d %H")
2022-01-06 20:40:03 +00:00
with open("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, numberOfv2+numberOfNonv2, dt))
2021-08-19 16:24:38 +00:00
#print("Num HSDir: {}".format(numberOfHSDir))
#print("< 0.4.6: {}".format(numberOfv2HSDir))
#print(">= 0.4.6: {}".format(numberOfNonv2HSDir))
#print()
2021-08-19 16:24:38 +00:00
#print("< 0.4.6: {}".format(numberOfv2))
#print(">= 0.4.6: {}".format(numberOfNonv2))
#print("DT: {}".format(dt))