def search_shodan(cmd, max_thread, limit): global threads api = ShodanAPI().get_api() # Wrap the request in a try/ except block to catch errors try: # Search Shodan results = api.search(cmd) print 'There are ' + str(results['total']) + ' results.' # calculing the number of pages if (limit is None): nb_pages = math.ceil(int(results['total']) / 100.0) else: min_res = min(int(results['total']), int(limit)) nb_pages = math.ceil(min_res / 100.0) ShodanAPI().set_results(results) i = 2 while (i <= nb_pages): # Launch threads for each page thread = ThreadShodanAPISearcher(cmd, i) thread.start() threads.append(thread) i = i + 1 # result should be equal but to be sure >= if ((i-1) >= max_thread): for thread in threads: thread.join() threads = [] # wait for all threads to finish for thread in threads: thread.join() print_info(ShodanAPI().get_results()) except Exception, e: print 'Error: %s' % e
def search_shodan(cmd, max_thread, limit): global threads api = ShodanAPI().get_api() # Wrap the request in a try/ except block to catch errors try: # Search Shodan results = api.search(cmd) print 'There are ' + str(results['total']) + ' results.' # calculing the number of pages if (limit is None): nb_pages = math.ceil(int(results['total']) / 100.0) else: min_res = min(int(results['total']), int(limit)) nb_pages = math.ceil(min_res / 100.0) ShodanAPI().set_results(results) i = 2 while (i <= nb_pages): # Launch threads for each page thread = ThreadShodanAPISearcher(cmd, i) thread.start() threads.append(thread) i = i + 1 # result should be equal but to be sure >= if ((i - 1) >= max_thread): for thread in threads: thread.join() threads = [] # wait for all threads to finish for thread in threads: thread.join() print_info(ShodanAPI().get_results()) except Exception, e: print 'Error: %s' % e
def run(self): api = ShodanAPI().get_api() res = api.search(self.command, page=self.page) ShodanAPI().set_results(res)