Skip to content

Setup JSON output for domains scripts #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
36 changes: 24 additions & 12 deletions domain/domain_dnsrecords.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python

import json
import base
import sys
import dns.resolver
from termcolor import colored

ENABLED = True
OUTPUT_TYPE = "console"


class style:
Expand All @@ -18,11 +20,13 @@ def fetch_dns_records(domain, rec_type):
answers = dns.resolver.query(domain, rec_type)
rec_list = []
for rdata in answers:
rec_list.append(rdata)
rec_list.append(rdata.to_text())
return rec_list
except:
return colored("No Records Found", 'red')

if(OUTPUT_TYPE == "console"):
return colored("No Records Found", 'red')
if(OUTPUT_TYPE == "json"):
return list()

def parse_dns_records(domain):
dict_dns_record = {}
Expand All @@ -37,27 +41,35 @@ def parse_dns_records(domain):


def banner():
print colored(style.BOLD + '---> Finding DNS Records.\n' + style.END, 'blue')
if(OUTPUT_TYPE == "console"):
print colored(style.BOLD + '---> Finding DNS Records.\n' + style.END, 'blue')


def main(domain):
return parse_dns_records(domain)


def output(data, domain=""):
for x in data.keys():
print x
if "No" in data[x] and "Found" in data[x]:
print "\t%s" % data[x]
else:
for y in data[x]:
print "\t%s" % y
print "\n-----------------------------\n"
if(OUTPUT_TYPE == "console"):
for x in data.keys():
print x
if "No" in data[x] and "Found" in data[x]:
print "\t%s" % data[x]
else:
for y in data[x]:
print "\t%s" % y
print "\n-----------------------------\n"

if(OUTPUT_TYPE == "json"):
print(json.dumps(data))


if __name__ == "__main__":
try:
domain = sys.argv[1]
if(len(sys.argv) > 2):
OUTPUT_TYPE = sys.argv[2]

banner()
result = main(domain)
output(result, domain)
Expand Down
34 changes: 26 additions & 8 deletions domain/domain_whois.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
#!/usr/bin/env python

import json
import base
import sys
import whois
from termcolor import colored
import time
import datetime

ENABLED = True

OUTPUT_TYPE = "console"

class style:
BOLD = '\033[1m'
END = '\033[0m'


def whoisnew(domain):
w = whois.whois(domain)
return dict(w)


def banner():
print colored(style.BOLD + '---> Finding Whois Information.' + style.END, 'blue')

if(OUTPUT_TYPE == "console"):
print colored(style.BOLD + '---> Finding Whois Information.' + style.END, 'blue')

def main(domain):
return whoisnew(domain)


def output(data, domain=""):
print data
print "\n-----------------------------\n"

if(OUTPUT_TYPE == "console"):
print data
print "\n-----------------------------\n"

if(OUTPUT_TYPE == "json"):
js = {}
for i in data:
# convert iterables to json list
if(hasattr(data[i], '__iter__')):
js[i] = list()
for j in data[i]:
js[i].append(j)
# convert datetime to string
elif (isinstance(data[i], datetime.datetime)):
js[i] = data[i].strftime("%s")
else:
js[i] = str(data[i])

print json.dumps(js)

if __name__ == "__main__":
try:
domain = sys.argv[1]
if(len(sys.argv) > 2):
OUTPUT_TYPE=sys.argv[2]
banner()
result = main(domain)
output(result, domain)
Expand Down