-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dns_resolver.py
executable file
·80 lines (63 loc) · 2.16 KB
/
test_dns_resolver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import datetime
import time
from routing_aware_dns_resolver import *
today = datetime.datetime.now()
def parse_args():
parser = argparse.ArgumentParser()
# Domain list csv file.
parser.add_argument("-d", "--domains",
default="./top-1m.csv")
parser.add_argument("-e", "--errors",
default=f"./errors-{today.year}-{today.month}-{today.day} {today.hour}-{today.minute}-{today.second}.log")
parser.add_argument("-r", "--results",
default=f"./results-{today.year}-{today.month}-{today.day} {today.hour}-{today.minute}-{today.second}.log")
parser.add_argument("-l", "--latencies",
default=f"./latencies-{today.year}-{today.month}-{today.day} {today.hour}-{today.minute}-{today.second}.log")
return parser.parse_args()
resultsFileName = None
def writeResult(result):
with open(resultsFileName, "a") as f:
f.write(result)
f.write("\n")
errorFileName = None
def writeError(e):
with open(errorFileName, "a") as f:
f.write(e)
f.write("\n")
latencyFileName = None
def writeLatency(l):
with open(latencyFileName, "a") as f:
f.write(l)
f.write("\n")
lookupLatencies = []
errors = []
def main(args):
global resultsFileName, errorFileName, latencyFileName
resultsFileName = args.results
errorFileName = args.errors
latencyFileName = args.latencies
domainsResolved = 0
for line in open(args.domains):
sline = line.strip()
if sline == "":
continue
splitLine = sline.split(",")
domain = splitLine[1]
try:
startTime = time.time()
result = performFullLookupForName(domain)
endTime = time.time()
latency = endTime - startTime
writeResult(f"Domain: {domain}, result: {result}")
writeLatency(f"Domain: {domain}, latency: {latency}")
except ValueError as v:
writeError(f"Domain: {domain}, value error: {v}")
except Exception as e:
writeError(f"Domain: {domain}, other error: {e}")
domainsResolved += 1
print(f"Domains resolved: {domainsResolved}")
if __name__ == '__main__':
main(parse_args())