Skip to content

Instantly share code, notes, and snippets.

@anmolj7
Created December 7, 2019 20:55
Show Gist options
  • Save anmolj7/68e72eda4aee2e01d17358c5ca6d85f2 to your computer and use it in GitHub Desktop.
Save anmolj7/68e72eda4aee2e01d17358c5ca6d85f2 to your computer and use it in GitHub Desktop.
from shodan import Shodan
import subprocess as sp
import requests
api = Shodan("iG0r3X7hjuIVWlopWTyy8DPO7eIF3wEG")
def clrscr():
sp.call(["clear"], shell=True)
def breakline():
print("-"*60)
def shodan_ip_search(shodan_obj, ip_to_search):
port_target = []
result = ""
try:
print("\nSearching Shodan for info about " + ip_to_search + "...\n")
result = shodan_obj.host(ip_to_search)
try:
for i in result['data']:
print('Port: %s' % i['port'])
port_target.append(i['port'])
except Exception as e:
print(str(e))
except Exception as e:
print(str(e))
return port_target
def main():
breakline()
print("1) For Your IP.")
print("2) Shodan Search to scan IPs, Hostnames, ports.")
print("3) Scan a specific Host.")
print("0) To Exit.")
breakline()
choice = int(input("Your choice: "))
breakline()
if choice == 1:
print(f'Your public ip is: {requests.get("https://ident.me").content.decode("utf8")}')
elif choice == 2:
query = input("Input your query to search: ")
results = api.search(query)
for result in results['matches']:
print(result['ip_str'])
elif choice == 3:
ip = input("Enter the ip: ")
shodan_ip_search(api, ip)
elif choice == 0:
exit()
main()
clrscr()
main()
@AnonQuebec
Copy link

@anmolj7

Don't know if you'r still active on Git but you should change line 5 for

api = Shodan("ShodanAPIKey")
since this is your own key

Nice usefull script btw

`from shodan import Shodan
import subprocess as sp
import requests

api = Shodan("ShodanAPIKey")

def clrscr():
sp.call(["clear"], shell=True)

def breakline():
print("-"*60)

def shodan_ip_search(shodan_obj, ip_to_search):
port_target = []
result = ""
try:
print("\nSearching Shodan for info about " + ip_to_search + "...\n")
result = shodan_obj.host(ip_to_search)
try:
for i in result['data']:
print('Port: %s' % i['port'])
port_target.append(i['port'])
except Exception as e:
print(str(e))
except Exception as e:
print(str(e))
return port_target

def main():
breakline()
print("1) For Your IP.")
print("2) Shodan Search to scan IPs, Hostnames, ports.")
print("3) Scan a specific Host.")
print("0) To Exit.")
breakline()
choice = int(input("Your choice: "))
breakline()

if choice == 1:
    print(f'Your public ip is: {requests.get("https://ident.me").content.decode("utf8")}')
elif choice == 2:
    query = input("Input your query to search: ")
    results = api.search(query)
    for result in results['matches']:
        print(result['ip_str'])
elif choice == 3:
    ip = input("Enter the ip: ")
    shodan_ip_search(api, ip)
elif choice == 0:
    exit()
main()

clrscr()
main()`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment