forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (34 loc) · 966 Bytes
/
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
# DNS VERIFIER
import json
import sys
from collections import OrderedDict
import dns.resolver
def checker(dns_val=None) -> OrderedDict:
ip_values = None
avail = False
if dns_val is None:
raise ValueError("Sorry DNS not found, 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
print("Enter the DNS:")
dns_val=input()
try:
response = checker(dns_val=dns_val)
except Exception as err:
print(f"error: {err}")
sys.exit(1)
print(json.dumps(response, indent=4))
sys.exit(0)