Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Misc/DNS Verifier/DNS_Verifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
26 changes: 26 additions & 0 deletions Misc/DNS Verifier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## DNSLU - DNS LOOK UP

## Setup and activate virtual environment :
For Unix based systems please execute the following command to create venv and install requirements.
```
make init
source .venv/bin/activate
```

Domain availability checker (DNS lookup) #138

Usage:

python dnslu.py --dns <DNS>


output:

python dnslu.py --dns google.com
{
"DNS": "google.com",
"IP": [
"172.217.172.78"
],
"AVAIL": false
}
1 change: 1 addition & 0 deletions Misc/DNS Verifier/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dnspython==2.0.0