From b1efe75eee5660571fccd361c17d132746316bf7 Mon Sep 17 00:00:00 2001 From: "Christopher K. Hoadley" Date: Sat, 7 Dec 2019 17:24:09 -0600 Subject: [PATCH] Remove timeout global and make it available on the command line. Change default to no timeout. --- sherlock.py | 50 ++++++++++++++++++++++++++++++++++++++++++++------ tests/base.py | 4 +++- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/sherlock.py b/sherlock.py index d329789..aec4425 100755 --- a/sherlock.py +++ b/sherlock.py @@ -30,10 +30,9 @@ __version__ = "0.9.12" amount = 0 -global proxy_list, timeout_limit +global proxy_list proxy_list = [] -timeout_limit = 10 class ElapsedFuturesSession(FuturesSession): """ @@ -135,7 +134,8 @@ def get_response(request_future, error_type, social_network, verbose=False, retr return None, "", -1 -def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False, proxy=None, print_found_only=False): +def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False, + proxy=None, print_found_only=False, timeout=None): """Run Sherlock Analysis. Checks for existence of username on various social media sites. @@ -148,6 +148,8 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False, pr tor -- Boolean indicating whether to use a tor circuit for the requests. unique_tor -- Boolean indicating whether to use a new tor circuit for each request. proxy -- String indicating the proxy URL + timeout -- Time in seconds to wait before timing out request. + Default is no timeout. Return Value: Dictionary containing results from report. Key of dictionary is the name @@ -248,12 +250,12 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False, pr future = request_method(url=url_probe, headers=headers, proxies=proxies, allow_redirects=allow_redirects, - timeout=timeout_limit + timeout=timeout ) else: future = request_method(url=url_probe, headers=headers, allow_redirects=allow_redirects, - timeout=timeout_limit + timeout=timeout ) # Store future in data for access later @@ -362,6 +364,31 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False, pr return results_total +def timeout_check(value): + """Check Timeout Argument. + + Checks timeout for validity. + + Keyword Arguments: + value -- Time in seconds to wait before timing out request. + + Return Value: + Floating point number representing the time (in seconds) that should be + used for the timeout. + + NOTE: Will raise an exception if the timeout in invalid. + """ + from argparse import ArgumentTypeError + + try: + timeout = float(value) + except: + raise ArgumentTypeError(f"Timeout '{value}' must be a number.") + if timeout <= 0: + raise ArgumentTypeError(f"Timeout '{value}' must be greater than 0.0s.") + return timeout + + def main(): # Colorama module's initialization. init(autoreset=True) @@ -422,6 +449,14 @@ def main(): "The script will check if the proxies supplied in the .csv file are working and anonymous." "Put 0 for no limit on successfully checked proxies, or another number to institute a limit." ) + parser.add_argument("--timeout", + action="store", metavar='TIMEOUT', + dest="timeout", type=timeout_check, default=None, + help="Time (in seconds) to wait for response to requests. " + "Default timeout of 60.0s." + "A longer timeout will be more likely to get results from slow sites." + "On the other hand, this may cause a long delay to gather all results." + ) parser.add_argument("--print-found", action="store_true", dest="print_found_only", default=False, help="Do not output sites where the username was not found." @@ -576,7 +611,10 @@ def main(): results = {} results = sherlock(username, site_data, verbose=args.verbose, - tor=args.tor, unique_tor=args.unique_tor, proxy=args.proxy, print_found_only=args.print_found_only) + tor=args.tor, unique_tor=args.unique_tor, + proxy=args.proxy, + print_found_only=args.print_found_only, + timeout=args.timeout) exists_counter = 0 for website_name in results: diff --git a/tests/base.py b/tests/base.py index 4f1bee7..da34f95 100644 --- a/tests/base.py +++ b/tests/base.py @@ -43,6 +43,7 @@ class SherlockBaseTest(unittest.TestCase): self.verbose=False self.tor=False self.unique_tor=False + self.timeout=None return @@ -104,7 +105,8 @@ class SherlockBaseTest(unittest.TestCase): site_data, verbose=self.verbose, tor=self.tor, - unique_tor=self.unique_tor + unique_tor=self.unique_tor, + timeout=self.timeout ) for site, result in results.items(): with self.subTest(f"Checking Username '{username}' "