diff --git a/DOH-Dig/README.md b/DOH-Dig/README.md new file mode 100644 index 0000000..034f1f7 --- /dev/null +++ b/DOH-Dig/README.md @@ -0,0 +1,45 @@ +# doh-dig + +A python dig script that returns json dns record lookup using cloud flares DNS servers. + +## Usage +``` +Usage: + doh-dig type + doh-dig ptr + doh-dig (-h | --help) + doh-dig --version + +``` + +### requirements +* [docopt]: https://github.com/docopt/docopt +* [requests]: https://pypi.org/project/requests/ + +### Examples + +#### lookup and A record for google.com +./doh-dig type a google.com |python -m json.tool + ``` + [ + { + "name": "google.com.", + "type": 1, + "TTL": 235, + "data": "172.217.19.174" + } +] +``` + +#### lookup reverse record for an IP + ./doh-dig ptr 1.1.1.1 |python -m json.tool + ``` + [ + { + "name": "1.1.1.1.in-addr.arpa.", + "type": 12, + "TTL": 1345, + "data": "one.one.one.one." + } +] +``` \ No newline at end of file diff --git a/DOH-Dig/doh-dig b/DOH-Dig/doh-dig new file mode 100755 index 0000000..19402a8 --- /dev/null +++ b/DOH-Dig/doh-dig @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# Author: @awsumco + +"""DNS OF HTTPS - DIG + +Usage: + doh-dig type + doh-dig ptr + doh-dig (-h | --help) + doh-dig --version + +Options: + -h --help Show this screen. + --version Show version. + +""" +from docopt import docopt +from pprint import pprint as pp +from sys import exit +import ipaddress, json + +def CloudFlareLookup(type,record): + import requests + headers = {'accept': 'application/dns-json'} + url = "https://1.1.1.1/dns-query?name=%s&type=%s" % (record,type) + r = requests.get(url, headers=headers) + j_data = json.loads(r.text) + try: + return(j_data['Answer']) + except: + return(j_data['Question']) + + +valid_types = ['A','MX','PTR','SRV','TXT','NS'] + +if __name__ == '__main__': + arguments = docopt(__doc__, version='doh-dig 0.1') + if arguments['type']: + t = arguments[''].upper() + r = arguments[''].lower() + if t not in valid_types: + exit('invalid type') + x = CloudFlareLookup(t,r) + print(json.dumps(x)) + elif arguments['ptr']: + ip = arguments[''] + arpa = ipaddress.ip_address(ip).reverse_pointer + x = CloudFlareLookup('PTR',arpa) + print(json.dumps(x)) + else: + print(arguments) + diff --git a/DOH-Dig/requirements.txt b/DOH-Dig/requirements.txt new file mode 100644 index 0000000..dc8ac66 --- /dev/null +++ b/DOH-Dig/requirements.txt @@ -0,0 +1,2 @@ +docopt +requests diff --git a/README.md b/README.md index 96e4bb8..7548e11 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ So far, the following projects have been integrated to this repo: | [Crypt socket](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Crypt_Socket)|[Willian GL](https://github.com/williangl) | |[Current City Weather](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Current_City_Weather) |[Jesse Bridge](https://github.com/jessebridge) | |[Directory organizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Directory-organizer) | [Athul P](https://github.com/athulpn) | +|[DOH DIG](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/DOH-Dig/) | [Ryan](https://github.com/awsumco) | |[Excel Files Merger](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Excel_Files_Merger) | [Andrei N](https://github.com/Andrei-Niculae)| |[Excel to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Excel_to_ListofList) | [Nitish Srivastava](https://github.com/nitish-iiitd)| |[Extended_ip_address_info](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/extended_ip_address_info) | [hafpaf](https://github.com/hafpaf)|