-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_check.py
executable file
·63 lines (54 loc) · 1.39 KB
/
dns_check.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
#! /usr/bin/env python
import argparse
import dns.resolver
from rich.table import Table
from rich.console import Console
args_parser = argparse.ArgumentParser(
prog="dns-check",
description="Searches DNS for A, CNAME, MX, TXT, AAAA and SRV records for the specified FQDN.",
)
args_parser.add_argument(
"domain",
metavar="domainname",
type=str,
help="Enter the FQDN to search DNS records for.",
)
args_parser.add_argument(
"-ns",
"--nameserver",
metavar="nameserver",
type=str,
help="Enter a custom nameserver.",
required=False,
)
def get_records(domain: str) -> str:
"""
:param domain
:return str
"""
record_types = [
"A",
"CNAME",
"MX",
"TXT",
"AAAA",
"SRV",
]
console = Console()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Record")
table.add_column("Value")
for record in record_types:
try:
resolver = dns.resolver
if args.nameserver:
resolver.nameservers = [args.nameserver]
answers = resolver.resolve(domain, record)
for rdata in answers:
table.add_row(record, rdata.to_text())
except:
continue
console.print(table) # or pass
if __name__ == "__main__":
args = args_parser.parse_args()
get_records(args.domain)