-
Notifications
You must be signed in to change notification settings - Fork 2
/
status.py
executable file
·62 lines (48 loc) · 1.67 KB
/
status.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
#!/usr/bin/env python3
import sys
from argparse import ArgumentParser
from datetime import datetime
from pprint import pprint
import dns.query
import adns
from desec import frontend_servers
def all_equal(l):
if len(l) == 0:
return True
l = list(l)
for i in range(1, len(l)):
if l[i] != l[0]:
return False
return True
def filter_query_rrset(response, qname, qtype):
try:
return response.find_rrset(dns.message.ANSWER, qname, dns.rdataclass.IN, qtype)
except AttributeError:
return response
except KeyError:
return None
def main(args):
parser = ArgumentParser(
prog='status',
description='Queries all deSEC frontends with a given question and returns the result(s).'
)
parser.add_argument('rdtype', help="record set type to be queried", type=str)
parser.add_argument('name', help="DNS name to be queried", type=str)
args = parser.parse_args(args)
print(f'{datetime.now()} Querying {len(frontend_servers)} servers for {args.rdtype} {args.name} ...')
qname = dns.name.from_text(args.name)
qtype = dns.rdatatype.from_text(args.rdtype)
responses = adns.query_all(
where_list=frontend_servers,
q=dns.message.make_query(qname, qtype)
)
# Filter responses
filtered_responses = {w: str(filter_query_rrset(r, qname, qtype)) for w, r in responses.items()}
if all_equal(filtered_responses.values()):
print(f'All servers returned:\n\n{next(iter(filtered_responses.values()))}')
else:
pprint(filtered_responses)
print('@'*80)
print('Server responses differ.')
if __name__ == '__main__':
main(sys.argv[1:])