-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNS_verifier.py
More file actions
58 lines (48 loc) · 1.42 KB
/
DNS_verifier.py
File metadata and controls
58 lines (48 loc) · 1.42 KB
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
#!/usr/bin/python3
# code: utf-8
import json
import sys
from collections import OrderedDict
import dns.resolver
def dac(dns_val=None) -> OrderedDict:
"""
Domain Availability Checker (DNS lookup)
:param _dns: URL string
:return: Availability [True, False]
"""
ip_values = None
avail = False
if dns_val is None:
raise ValueError("Sorry, DNS is needed")
if isinstance(dns_val, str) is False:
raise TypeError("Sorry, \'DNS\' must be type \'str\'")
try:
output = dns.resolver.resolve(dns_val, 'A')
ip_values = [ipval.to_text() for ipval in output]
except dns.resolver.NXDOMAIN:
avail = True
return OrderedDict([
("DNS", dns_val),
("IP", ip_values),
("AVAIL", avail),
])
if __name__ == '__main__':
dns_val = None
option = None
if len(sys.argv) > 1:
if '--dns' in sys.argv:
d_index = sys.argv.index('--dns')
if d_index == sys.argv.index(sys.argv[-1:][0]):
print("Sorry, DNS was not specified")
sys.exit(1)
dns_val = sys.argv[sys.argv.index('--dns') + 1]
else:
print("help:\nuse \'--dns\' for DNS specification")
sys.exit(1)
try:
response = dac(dns_val=dns_val)
except Exception as err:
print(f"error: {err}")
sys.exit(1)
print(json.dumps(response, indent=4))
sys.exit(0)