From 20b63626e2cfce44d6c0b0c869270af2418838e9 Mon Sep 17 00:00:00 2001 From: Krishna13515 Date: Mon, 17 Oct 2022 11:30:06 +0545 Subject: [PATCH] added DNS verifier script --- Misc/DNS Verifier/DNS_Verifier.py | 58 ++++++++++++++++++++++++++++++ Misc/DNS Verifier/README.md | 26 ++++++++++++++ Misc/DNS Verifier/requirements.txt | 1 + 3 files changed, 85 insertions(+) create mode 100644 Misc/DNS Verifier/DNS_Verifier.py create mode 100644 Misc/DNS Verifier/README.md create mode 100644 Misc/DNS Verifier/requirements.txt diff --git a/Misc/DNS Verifier/DNS_Verifier.py b/Misc/DNS Verifier/DNS_Verifier.py new file mode 100644 index 0000000..bfff4c6 --- /dev/null +++ b/Misc/DNS Verifier/DNS_Verifier.py @@ -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) diff --git a/Misc/DNS Verifier/README.md b/Misc/DNS Verifier/README.md new file mode 100644 index 0000000..5e5c324 --- /dev/null +++ b/Misc/DNS Verifier/README.md @@ -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 + + +output: + + python dnslu.py --dns google.com + { + "DNS": "google.com", + "IP": [ + "172.217.172.78" + ], + "AVAIL": false + } \ No newline at end of file diff --git a/Misc/DNS Verifier/requirements.txt b/Misc/DNS Verifier/requirements.txt new file mode 100644 index 0000000..c186c6c --- /dev/null +++ b/Misc/DNS Verifier/requirements.txt @@ -0,0 +1 @@ +dnspython==2.0.0