Created
February 4, 2019 20:33
-
-
Save darkerego/fc17cbdfda9657126db4ea4ce324c297 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
#!/usr/bin/python3.6 | |
""" | |
Whoxy API Tool - Query whoxy.com for reverse whois data | |
Darkerego, 2019 | |
""" | |
import argparse | |
import requests | |
import json | |
import config """ create a file called `config.py` and set your api key: | |
""" api_key = 'yourapikeyhere' | |
def pp_json(json_thing, sort=True, indents=4): | |
""" | |
:param json_thing: data to prettify | |
:param sort: sort index | |
:param indents: lines | |
:return: None, just print | |
""" | |
if type(json_thing) is str: | |
print(json.dumps(json.loads(json_thing), sort_keys=sort, indent=indents)) | |
else: | |
print(json.dumps(json_thing, sort_keys=sort, indent=indents)) | |
return None | |
def query_api(identifier, query): | |
""" | |
:param identifier: Search by | |
:param query: Data to search for | |
:return: | |
""" | |
try: | |
api_key = config.api_key | |
except ImportError: | |
raise ValueError('Cannot find api_key in config file config.py') | |
else: | |
res = requests.get('http://api.whoxy.com/?key=' + api_key + '&reverse=whois&+ ' + identifier + '=' + query) | |
if res.status_code != 200: | |
raise ValueError("Whoxy API key seems to have been rejected or you have exceeded usage limits.", False) | |
else: | |
ret = json.loads(res.content) | |
# print(ret) | |
pp_json(ret) | |
def get_args(): | |
""" | |
Argparse - Specify either -i / --interactive, and than -q / --query , (data to search for) , or -f/--file, | |
to itertate through a list of queries, querytype specified with -s ('name', 'email', 'company', or 'keyword) | |
:return: args | |
""" | |
parser = argparse.ArgumentParser() | |
query_options = parser.add_argument_group("Query Options") | |
query_options.add_argument("-i", "--interactive", action="store_true", dest="interactive", | |
help='Input email in interactive mode. Specify query with <-q/--query flag>') | |
query_options.add_argument("-f", "--list_filename", dest="list_filename", | |
help="Filename containing list of queries") | |
# query_options = parser.add_argument_group("Query Options"), | |
query_options.add_argument("-s", "--search_identifier", dest="search_identifier", | |
help="Identify to search by. Valid identifiers are: " | |
"'name', 'email', 'company', and 'keyword' ") | |
query_options.add_argument("-q", "--query", dest="query", | |
help="Data to query (<--interactive --query '[email protected]'>?") | |
return parser.parse_args() | |
""" | |
Program Start | |
""" | |
if __name__ == "__main__": | |
args = get_args() | |
if args.interactive: | |
print('Interactive mode') | |
if args.list_filename: | |
raise ValueError('Specifiy either interfactive mode -i, or file with list of queries, -f') | |
else: | |
if args.search_identifier: | |
identifier = args.search_identifier | |
print('Searching by %s' % identifier) | |
if args.query: | |
query = args.query | |
print('Query: %s' % query) | |
query_api(identifier, query) | |
else: | |
raise ValueError("Specify a keyword to query <-q/--query> keyword") | |
else: | |
raise ValueError("Specify an identifier. Valid: 'name', 'email', 'company', 'keyword'") | |
if args.list_filename: | |
infile = args.list_filename | |
identifier = args.search_identifier | |
print("Opening %s " % infile) | |
with open(infile) as f: | |
infile = f.readlines() | |
for query in infile: | |
print("Query: %s)" % query) | |
query_api(identifier, query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment