Advertisement
YuukiHaruka

shodan_scanner.py

May 18th, 2022
543
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from shodan import Shodan
  2. import subprocess as sp
  3. import requests
  4.  
  5. api = Shodan("iG0r3X7hjuIVWlopWTyy8DPO7eIF3wEG")
  6.  
  7. def clrscr():
  8.     sp.call(["clear"], shell=True)
  9.  
  10. def breakline():
  11.     print("-"*60)
  12.  
  13. def shodan_ip_search(shodan_obj, ip_to_search):
  14.     port_target = []
  15.     result = ""
  16.     try:
  17.         print("\nSearching Shodan for info about " + ip_to_search + "...\n")
  18.         result = shodan_obj.host(ip_to_search)
  19.         try:
  20.             for i in result['data']:
  21.                print('Port: %s' % i['port'])
  22.                port_target.append(i['port'])
  23.         except Exception as e:
  24.             print(str(e))
  25.     except Exception as e:
  26.         print(str(e))
  27.     return port_target
  28.  
  29. def main():
  30.     breakline()
  31.     print("1) For Your IP.")
  32.     print("2) Shodan Search to scan IPs, Hostnames, ports.")
  33.     print("3) Scan a specific Host.")
  34.     print("0) To Exit.")
  35.     breakline()
  36.     choice = int(input("Your choice: "))
  37.     breakline()
  38.    
  39.     if choice == 1:
  40.         print(f'Your public ip is: {requests.get("https://ident.me").content.decode("utf8")}')
  41.     elif choice == 2:
  42.         query = input("Input your query to search: ")
  43.         results = api.search(query)
  44.         for result in results['matches']:
  45.             print(result['ip_str'])
  46.     elif choice == 3:
  47.         ip = input("Enter the ip: ")
  48.         shodan_ip_search(api, ip)
  49.     elif choice == 0:
  50.         exit()
  51.     main()
  52.  
  53. clrscr()
  54. main()
  55.  
Advertisement
RAW Paste Data Copied
Advertisement