-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·69 lines (59 loc) · 2.55 KB
/
main.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
#!/usr/bin/python3
import dns
import argparse
from query_parser import RecordType
def main():
class Debug:
def send_debug_function(self, address):
print("send query to " + address)
def recv_debug_function(self, responses):
for response in responses:
print("Response:")
print("id: {}, flags: {}, questions: {}, answers: {}, "
"authority: {}, additional: {}".format(
response.id, str(response.flags),
len(response.questions),
len(response.answers), len(response.authorities),
len(response.additional)
))
print("Questions:")
for question in response.questions:
print(question)
print("Answers:")
for answer in response.answers:
print(answer)
print("Authority:")
for authority in response.authorities:
print(authority)
print("Additional:")
for additional in response.additional:
print(additional)
parser = argparse.ArgumentParser()
parser.add_argument('--do_recursive', action='store_true')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--tcp', action='store_true')
parser.add_argument('-type', action='store', dest='type', default="A",
choices=["A", "AAAA", "MX", "NS"])
parser.add_argument('-timeout', action='store', dest='timeout',
default=dns.DEFAULT_TIMEOUT, type=int)
parser.add_argument('domain_name')
parser.add_argument('server', nargs='?', default=None)
parser.add_argument('port', nargs='?', type=int, default=dns.UDP_PORT)
arguments = parser.parse_args()
debug = Debug() if arguments.debug else None
dns_class = dns.DNS(is_recursion_desired=arguments.do_recursive,
root_server=arguments.server,
port=arguments.port, timeout=arguments.timeout,
debug_class=debug, tcp=arguments.tcp)
record_types = {
"A": RecordType.Ipv4,
"AAAA": RecordType.Ipv6,
"MX": RecordType.MailExchanger,
"NS": RecordType.DnsServer,
}
answers = dns_class.get_answers(arguments.domain_name,
record_types[arguments.type])
for answer in answers:
print(answer.data)
if __name__ == '__main__':
main()