Last active
May 6, 2023 11:17
-
-
Save dirtyak/e4143ffeb8f9a0ca1ec19b4d666318d4 to your computer and use it in GitHub Desktop.
Simple shodan command line in python
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
#!/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