mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
dig like over https
This commit is contained in:
parent
760ba8492c
commit
d4f2ddfb3c
45
DOH-Dig/README.md
Normal file
45
DOH-Dig/README.md
Normal file
|
@ -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 <type> <record>
|
||||||
|
doh-dig ptr <ip>
|
||||||
|
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."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
52
DOH-Dig/doh-dig
Executable file
52
DOH-Dig/doh-dig
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Author: @awsumco
|
||||||
|
|
||||||
|
"""DNS OF HTTPS - DIG
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
doh-dig type <type> <record>
|
||||||
|
doh-dig ptr <ip>
|
||||||
|
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['<type>'].upper()
|
||||||
|
r = arguments['<record>'].lower()
|
||||||
|
if t not in valid_types:
|
||||||
|
exit('invalid type')
|
||||||
|
x = CloudFlareLookup(t,r)
|
||||||
|
print(json.dumps(x))
|
||||||
|
elif arguments['ptr']:
|
||||||
|
ip = arguments['<ip>']
|
||||||
|
arpa = ipaddress.ip_address(ip).reverse_pointer
|
||||||
|
x = CloudFlareLookup('PTR',arpa)
|
||||||
|
print(json.dumps(x))
|
||||||
|
else:
|
||||||
|
print(arguments)
|
||||||
|
|
2
DOH-Dig/requirements.txt
Normal file
2
DOH-Dig/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
docopt
|
||||||
|
requests
|
Loading…
Reference in New Issue
Block a user