Skip to content

Commit

Permalink
Adding whois search module
Browse files Browse the repository at this point in the history
Added code with whois search module
- Showing alot of raw data
will work to suppress large data

- Added some color and box style for displaying 
 Will use them in future
  • Loading branch information
iAbdullahMughal committed Dec 9, 2021
1 parent 94c3e86 commit 6662af3
Show file tree
Hide file tree
Showing 6 changed files with 1,217 additions and 66 deletions.
407 changes: 348 additions & 59 deletions README.md

Large diffs are not rendered by default.

110 changes: 104 additions & 6 deletions domaintrails/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from domaintrails.core.parser import ColorPrint
from domaintrails.core.recon.dnslg import DnsLG as DomainDnsInformation
from domaintrails.core.resources import UserAgent
from domaintrails.core.recon.dbd_whois import DomainBigDataWhois


def index_in_list(a_list: list, index: int):
Expand Down Expand Up @@ -89,6 +90,29 @@ def dict_to_table(dict_data: dict):
return table_data


def repair_keys(key):
if "_" in key:
key = str(key).replace("_", " ")
return key.title()


def dict_to_list(dict_data, custom_header=None):
list_data = []
if "Useful_Information" in custom_header:
custom_header = None
for key in dict_data:
data_key = repair_keys(key)
if custom_header:
data_key = custom_header + " " + data_key
list_data.append(
[
data_key,
dict_data[key]
]
)
return list_data


def process_request(domain: str = None):
'''
This function is responsible for calling all the configured module and services in project. Following services are
Expand All @@ -115,17 +139,22 @@ def process_request(domain: str = None):
_info = "Domain is Registered"
else:
_info = "unable to find result."

ColorPrint.print_info("Domain Availability Result for %s : %s" % (domain, _info))
ColorPrint.print_info("\x1b[6;30;42mDomain Availability Result for %s : %s\x1b[0m" % (domain, _info))

dns_history = DomainHostHistory(str(domain))
__domain_history = dns_history.domain_history()

if __domain_history:
ColorPrint.print_info("DNS History Records")

ColorPrint.print_info("\x1b[6;30;42mDNS History Records\x1b[0m")
# '\x1b[6;33;40m' + "Historical Record Number" + '\x1b[0m',
table_data = [
[
"Old Web Host", "New Web Host", "Month / Year", "Zone Date", "Transaction"
"Old Web Host",
"New Web Host",
"Month / Year",
"Zone Date",
"Transaction",
]
]
for row in __domain_history:
Expand All @@ -143,16 +172,85 @@ def process_request(domain: str = None):
dns_information = DomainDnsInformation(str(domain))
dns_records = dns_information.download_report()

ColorPrint.print_info("\x1b[6;30;42mPrinting DNS Records Related To Domain\x1b[0m")
for dns_record in dns_records:
try:
record = dns_records[dns_record]
ColorPrint.print_info(record["title"])
ColorPrint.print_info(" " + record["title"])

records = record["records"]
print_table(dict_to_table(records))
except TypeError:
# @TODO: Check which kind of records are failing while converting into table and printing process
pass
domain_bigdata_whois = DomainBigDataWhois()
whois_data = domain_bigdata_whois.domain_whois()
if whois_data:
ColorPrint.print_info("\x1b[6;30;42mPrinting Whois Information\x1b[0m")
whois_record = [
["Record Type", "Record Data"]
]
for keys in whois_data.keys():
title = keys.replace("_", " ").title()

if keys in ["domain_record", "domain_registrant"]:
for key in whois_data[keys]:
whois_record.append(
[
str(key).replace("_", " ").title(),
whois_data[keys][key]
]
)

elif keys == "host_records":
for _keys in whois_data[keys]:
_title = str(_keys).replace("_", " ").upper()

print_table(whois_data[keys][_keys])

elif keys == "domain_whois":
for _keys in whois_data[keys]:
_child_data = whois_data[keys][_keys]
if isinstance(_child_data, str):
whois_record.append(
[
repair_keys(_keys),
_child_data
]
)
elif isinstance(_child_data, dict):
_child_title = repair_keys(_keys)
record = dict_to_list(_child_data, _child_title)
whois_record = whois_record + record
elif keys == "domain_whois_history":
for _keys in whois_data[keys]:
_child_title = repair_keys(_keys)
h_whois = [
['\x1b[6;33;40m' + "Historical Record Number" + '\x1b[0m',
'\x1b[6;33;40m%s\x1b[0m' % _child_title[-1]]
]
_child_data = whois_data[keys][_keys]
if isinstance(_child_data, str):
print(_child_data)
h_whois.append(
[
repair_keys(_keys),
_child_data
]
)
elif isinstance(_child_data, dict):
_child_title = repair_keys(_keys)
for _key in _child_data:
record = dict_to_list(_child_data[_key], _key)
h_whois = h_whois + record
print("\n")
print_table(h_whois)
else:
# @TODO: Check record information
# print(keys)
pass
print("")
print_table(whois_record)


__all__ = ["UserDomain", "UserAgent", "process_request", "DomainHostHistory"]
__all__ = ["UserDomain", "UserAgent", "process_request", "DomainHostHistory", "DomainBigDataWhois"]
2 changes: 1 addition & 1 deletion domaintrails/core/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def print_pass(message: str, end: str = '\n') -> None:
:rtype: None
"""

sys.stdout.write('\x1b[1;32m' + message.strip() + '\x1b[0m' + end)
sys.stdout.write('\n\x1b[1;32m' + message.strip() + '\x1b[0m' + end)

@staticmethod
def print_warn(message: str, end: str = '\n') -> None:
Expand Down

0 comments on commit 6662af3

Please sign in to comment.