Skip to content

Instantly share code, notes, and snippets.

@dirtyak
Last active May 6, 2023 11:17
Show Gist options
  • Save dirtyak/e4143ffeb8f9a0ca1ec19b4d666318d4 to your computer and use it in GitHub Desktop.
Save dirtyak/e4143ffeb8f9a0ca1ec19b4d666318d4 to your computer and use it in GitHub Desktop.
Simple shodan command line in python
#!/bin/env/python
import shodan
import os
import sys
import subprocess
from termcolor import cprint
from pyfiglet import figlet_format
######################################################
SHODAN_API_KEY = "ENTER_YOUR_API_KEY_HERE"
api = shodan.Shodan(SHODAN_API_KEY)
######################################################
# Clear the screen
def banner():
subprocess.call('clear', shell=True)
cprint(figlet_format('Shodan CLI', font='utopia'), 'white', attrs=['bold'])
query_credits = api.info()["query_credits"]
scan_credits = api.info()["scan_credits"]
#credits = api.info()
print "Query Credits = {}, Scan Credits = {}".format(query_credits, scan_credits)
print (60 * "-")
def help():
print os.popen("shodan").read()
def cmdline():
try:
while True:
#results = api.search(shodan_query)
query = raw_input('\033[92m' + 'Shodan > ' + '\033[0m')
if query == "help": query = "--help"
elif query == "exit": exit()
request = "shodan {}".format(query)
shodan_query = os.popen(request).read()
print shodan_query
except "Invalid API key":
print "invalid API Key"
except KeyboardInterrupt:
cprint ("CTRL+C", 'red')
sys.exit()
banner()
help()
cmdline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment