Last active
December 14, 2019 13:42
-
-
Save Mukundan314/ccf90ed2437542b8006778db0398a63c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import json | |
import sys | |
import urllib.request | |
API_KEY = "3fa3ce845ba490db8c3e47719672ed5d0ef66739" | |
USER_AGENT = "gci-reverse-whois/1.0" | |
def main(argv): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("query", type=str, help="Registrant Name or Email Address") | |
args = parser.parse_args(argv[1:]) | |
req = urllib.request.Request( | |
"https://api.viewdns.info/reversewhois/?q={}&apikey={}&output=json".format(args.query, API_KEY), | |
headers={"User-Agent": USER_AGENT}, | |
) | |
with urllib.request.urlopen(req) as res: | |
matches = json.load(res)["response"]["matches"] | |
max_domain_len = max([*map(lambda x: len(x["domain"]), matches), 6]) | |
max_created_date_len = max([*map(lambda x: len(x["created_date"]), matches), 12]) | |
max_registrar_len = max([*map(lambda x: len(x["registrar"]), matches), 9]) | |
seperator = "+{}+{}+{}+".format( | |
"-" * (max_domain_len + 2), | |
"-" * (max_created_date_len + 2), | |
"-" * (max_registrar_len + 2), | |
) | |
print(seperator) | |
print("| {} | {} | {} |".format( | |
"domain".center(max_domain_len), | |
"created date".center(max_created_date_len), | |
"registrar".center(max_registrar_len), | |
)) | |
print(seperator) | |
for match in matches: | |
print("| {} | {} | {} |".format( | |
match["domain"].center(max_domain_len), | |
match["created_date"].center(max_created_date_len), | |
match["registrar"].center(max_registrar_len), | |
)) | |
print(seperator) | |
if __name__ == "__main__": | |
main(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
import urllib.request | |
import lxml.html | |
USER_AGENT = "gci-reverse-whois/1.0" | |
def main(argv): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("query", type=str, help="Registrant Name or Email Address") | |
args = parser.parse_args(argv[1:]) | |
req = urllib.request.Request( | |
"https://viewdns.info/reversewhois/?q={}".format(args.query), | |
headers={"User-Agent": USER_AGENT}, | |
) | |
with urllib.request.urlopen(req) as res: | |
tables = lxml.html.parse(res).getroot().xpath("//table") | |
rows = [] if len(tables) == 5 else tables[3].xpath("//tr")[6:-3] | |
matches = [[child.text if child.text else '' for child in row.getchildren()] for row in rows] | |
max_domain_len = max([*map(lambda x: len(x[0]), matches), 6]) | |
max_created_date_len = max([*map(lambda x: len(x[1]), matches), 12]) | |
max_registrar_len = max([*map(lambda x: len(x[2]), matches), 9]) | |
seperator = "+{}+{}+{}+".format( | |
"-" * (max_domain_len + 2), | |
"-" * (max_created_date_len + 2), | |
"-" * (max_registrar_len + 2), | |
) | |
print(seperator) | |
print("| {} | {} | {} |".format( | |
"domain".center(max_domain_len), | |
"created date".center(max_created_date_len), | |
"registrar".center(max_registrar_len), | |
)) | |
print(seperator) | |
for match in matches: | |
print("| {} | {} | {} |".format( | |
match[0].center(max_domain_len), | |
match[1].center(max_created_date_len), | |
match[2].center(max_registrar_len), | |
)) | |
print(seperator) | |
if __name__ == "__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment