Lots of changes

Skip first 46 lines
Check running relays only
comment out downloading from collector
This commit is contained in:
HackerNCoder 2022-09-05 14:32:55 +00:00
parent f80eb9b0b8
commit c79eaed7c3

View file

@ -15,29 +15,30 @@ numberOfv2 = 0
consensus = "consensus"
url = "https://collector.torproject.org/recent/relay-descriptors/consensuses/2022-{}-00-00-consensus".format(dt)
print(url)
#url = "https://collector.torproject.org/recent/relay-descriptors/consensuses/2022-{}-00-00-consensus".format(dt)
#print(url)
r = requests.get(url)
os.remove(consensus)
with open(consensus,"wb") as output:
output.write(r.content)
#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")
consensus = open(consensus, "r")
for _ in range(46):
next(consensus)
while True:
line1 = file.readline()
line1 = consensus.readline()
if not line1: break
if re.search("^s", line1, re.IGNORECASE):
if re.search("^s.*Running", 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|18)|0.4.5.(11|12|13|14))", line2, re.IGNORECASE):
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):
if isHSDir:
numberOfNonv2HSDir += 1
numberOfNonv2 += 1
@ -45,13 +46,16 @@ while True:
if isHSDir:
numberOfv2HSDir += 1
numberOfv2 += 1
for _ in range(3):
next(consensus)
print(line1 + " " + line2 + " " + str(isHSDir))
dt = datetime.datetime.utcnow().strftime("%Y/%m/%d %H")
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, dt))
relaysCsv.write("{},{},{},{}\n".format(numberOfv2, numberOfNonv2, numberOfv2+numberOfNonv2, dt))
#print("Num HSDir: {}".format(numberOfHSDir))
#print("< 0.4.6: {}".format(numberOfv2HSDir))