How to use the shodan.WebAPI function in shodan

To help you get started, we’ve selected a few shodan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cr0hn / golismero-legacy / plugins / testing / recon / shodan.py View on Github external
results = []

        # Skip unsupported IP addresses.
        if info.version != 4:
            return
        ip = info.address
        parsed = netaddr.IPAddress(ip)
        if parsed.is_loopback() or \
           parsed.is_private()  or \
           parsed.is_link_local():
            return

        # Query Shodan for this host.
        try:
            key = self.get_api_key()
            api = WebAPI(key)
            shodan = api.host(ip)
        except Exception, e:
            tb = traceback.format_exc()
            Logger.log_error("Error querying Shodan: %s" % str(e))
            Logger.log_error_more_verbose(tb)
            return

        # Make sure we got the same IP address we asked for.
        if ip != shodan.get("ip", ip):
            Logger.log_error(
                "Shodan gave us a different IP address... weird!")
            Logger.log_error_verbose(
                "Old IP: %s - New IP: %s" % (ip, shodan["ip"]))
            ip = to_utf8( shodan["ip"] )
            info = IP(ip)
            results.append(info)
github PaulMcMillan / eagleeye_ce / eagleeye2 / tasks.py View on Github external
@celery.task(soft_time_limit=300, time_limit=600)
def get_shodan_results(page=1):
    logger.info("Fetching shodan results page: %s", page)
    api = shodan.WebAPI(API_KEY)
    try:
        res = api.search(QUERY, page=page)
    except shodan.api.WebAPIError:
        logger.info('Finished shodan results with %s page(s).', page -1)
    else:
        get_shodan_results.delay(page=page+1)
        for r in res.get('matches', []):
            get_screenshot.delay(r)
        return res
github Adastra-thw / pyHacks / attackTOR.py View on Github external
def __init__(self, queue, tid, cli) :
		threading.Thread.__init__(self)
		self.queue = queue
		self.tid = tid
        	self.cli = cli
		self.bruteForcePorts ={'ftpBrute':21, 'sshBrute':22}
		if self.cli.useShodan == True:
			#Using Shodan to search information about this machine in shodan database.
			log.info("[+] Shodan Activated. About to read the Development Key. ")
			if self.cli.shodanKey == None:
				#If the key is None, we can't use shodan.
				log.warn("[-] Shodan Key's File has not been specified. We can't use shodan without a valid key")
			else:
				#Read the shodan key and create the WebAPI object.
				shodanKey = open(self.cli.shodanKey).readline().rstrip('\n')
				self.shodanApi = WebAPI(shodanKey)
				log.info("[+] Connected to Shodan. ")
	def run(self) :
github ChrisTruncer / PenTestScripts / WebScripts / ShodanSearch.py View on Github external
def create_shodan_object():
    # Add your shodan API key here
    api_key = "TYPEAPIKEYHERE"

    shodan_object = shodan.WebAPI(api_key)

    return shodan_object
github DanMcInerney / device-pharmer / shodan_pharmer.py View on Github external
def shodan_search(search, apikey):
    if apikey:
        API_KEY = apikey
    else:
        API_KEY = 'ENTER YOUR API KEY HERE AND KEEP THE QUOTES'
    api = WebAPI(API_KEY)

    ips_found = []

    try:
        results = api.search('%s' % search)
        print '[+] Results: %s' % results['total']
        for r in results['matches']:
            ips_found.append(r['ip'])
        return ips_found
    except Exception as e:
        print '[!] Error:', e
github torque59 / Nosql-Exploitation-Framework / nosqlexp.py View on Github external
def shodan_frame(port):

	# Currently Supports query based on port Filter only and Displays Corresponding IP
	print colored("\n[!] Shodan Search Module For NoSQL Framework Launched.....",'yellow')
	api = WebAPI("API KEY GOES HERE")
	if port == 5984:
		query='{"couchdb":"Welcome","version":""}'
	else:
		query='port:%s'%(port)
	result = api.search(query)
	print colored("[-] Would Like to write the Results to a File",'green')
	choice=raw_input()
	if choice.lower()=='y':
		file=open('shodan-%s.txt'%(port),'w')
		for host in result['matches']:
			file.write(host['ip']+"\n")
		print colored('[-] File to %s/shodan-%s.txt'%(os.getcwd(),port),'green')
		file.close()
	else:

		print colored("[-] Printing Found IP \n",'blue')