-
Notifications
You must be signed in to change notification settings - Fork 0
/
donuts.py
executable file
·75 lines (55 loc) · 1.93 KB
/
donuts.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
"""
Created on January 5, 2012
@author - Ben Finke - @benfinke
DoNutS - DNS Testing and scoring tool
Send a series of DNS requests to a target DNS server and score the response time and the accuracy of the results.
Usage: ./donuts.py <DNS server> <file of targets> <number of DNS queries> <number of threads>
By default we do 10 DNS queries for each entry in the file and 1 thread. Output goes to screen.
"""
import socket
from sys import argv
from os.path import exists
import dns.resolver
from dns import resolver
script, server, infile, times = argv
numtimes = int(times)
text = open(infile)
site_key = {}
site_list = []
for line in text:
entry = (line.strip('\n')).split(',')
site_word = entry[0]
ip_value = entry[1]
site_key[site_word] = ip_value
site_list.append(site_word)
print site_key
print site_list
print "Welcome to DoNutS. Let's get started."
workingresolver = resolver.Resolver()
workingresolver.nameservers = [server]
print "Attempting DNS lookups against the following servers:"
for i in workingresolver.nameservers:
print i +"\n"
attempts = 1
i = 0
x = 0
good_result = 0
bad_result = 0
while attempts <= numtimes:
site = site_list[x]
result = workingresolver.query(site, "A")
#result = socket.gethostbyname(site)
for rdata in result:
addresult = rdata.address
print "Attempt number %d for %s results in %s.\n" % (attempts, site, addresult)
if addresult == site_key[site]:
print "Result matches expected value."
good_result += 1
else:
print "The value returned isn't what we expected. Recieved %s instead of %s." % (addresult, site_key[site])
bad_result += 1
attempts += 1
i += 1
x = i % 4 # use modulus to make sure the number stays in the range of sites we are using
print "Stats: Good results -> %d/%d Bad results -> %d/%d." % (good_result, numtimes, bad_result, numtimes)
print "Shutting down. Thanks for playing!"