Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions 39 Shodan-API-Simplified/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Shodan API Ease-of-Use

[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)

This project is adds functionality to a basic use of the Shodan API (NOT the shodan cli), allowing for ease-of-use, repeatability and storage.

You can add this program to PATH so you can call it from the CLI, renaming it to a shorter name would be best if you do this - Also, make sure you're in a directory where you don't mind having files saved.

## Usage
* Run the script with python
* ex. python shodan_ip_port_info.py
* Enter your shodan API key when prompted
* Follow prompts to choose options

## Output:
1. Run the python file and enter your API

![shodan1](https://user-images.githubusercontent.com/74668676/197636772-33a222ee-f466-4267-867f-0667146086f4.PNG)

------------------------------------------------------------------------------------------------------------------------------------

1.1. If your API key is stored in the directory in the file shodan_api.json - you can go straight to the program

![shodan_saved_api](https://user-images.githubusercontent.com/74668676/197637533-00abcd36-ee04-4ad5-a346-80b9b2bb276d.PNG)

** If you have reset your API key, you will have to delete shodan_api.json to input your new API key....for now.


------------------------------------------------------------------------------------------------------------------------------------


2. Data from your searches will be saved in the file directory.


![shodan3](https://user-images.githubusercontent.com/74668676/197636907-278f95b2-4462-4411-8d78-8872f4c8598f.PNG)


## Author
Written by [ajhissh](https://github.com/AJHissh)
4 changes: 4 additions & 0 deletions 4 Shodan-API-Simplified/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
shodan
requests
json
os
94 changes: 94 additions & 0 deletions 94 Shodan-API-Simplified/shodan-simplified.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import shodan
import requests
import json
import os


print('--------------WELCOME TO THE EASE-OF-USE SHODAN API PROGRAM---------------')
print('--------------------------------------------------------------------------')
print('😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎')

## Checks if there is a stored api key in shodan_api.json
try:
with open('shodan_api.json') as file:
api_key = json.load(file)
print("Successfully loaded pre-saved key")
except:
## If there is no shodan_api.json file, you will be requested to input one
api_key = input('Please enter your shodan api key to get started: ')
data = api_key
with open('shodan_api.json', 'w+') as outfile:
json.dump(data, outfile, indent=2)
finally:
print('Starting program.............')

## Stores your API key for current session
api = shodan.Shodan(api_key)

## Retrieves IP info from target IP address
def shodan_ip_info():
x = True
while x is True:
ip_add = input('enter target IP address: ')
try:
info = api.host(ip_add)
## Saves IP information into shodan_data.json
with open('shodan_data.json', 'w+') as datafile:
json.dump(info, datafile, indent=2)
print(info)
print('---------------------------------------------')
print(f"Output file has been saved at: {os.path.dirname(os.path.abspath(__file__))}\shodan_data.json")

## Throws an error if API key is invalid or if target IP has no information
except shodan.APIError as error:
print('Error:', error)
finally:
## Asks user for next steps
cont_or_exit = str(input('type "main" to go to main menu || type "again" to repeat || type "exit" to exit: '))
if cont_or_exit in ['Main', 'main', 'MAIN']:
main()
elif cont_or_exit in ['Again', 'again', 'AGAIN']:
x = True
elif cont_or_exit in ['Exit', 'exit', 'EXIT']:
x = False
exit()

## Targets an IP and finds open ports
def shodan_port_info():
x = True
while x == True:
try:
ip_add = input('enter target IP address: ')
## Retrieves Port information from target IP address
host = requests.get(f"https://internetdb.shodan.io/{ip_add}").json()
print(host)
## Saves Port information into a file called shodan_port_data.json
with open('shodan_port_data.json', 'w+') as portfile:
json.dump(host, portfile, indent=2)
print(f"Output file has been saved at: {os.path.dirname(os.path.abspath(__file__))}\shodan_port_data.json")
## No API Key needed for this process, so only notifies user if there was any Port information or not
except:
print('No port information for that IP')
finally:
## Asks user for next steps
cont_or_exit = str(input('type "main" to go to main menu || type "again" to repeat || type "exit" to exit: '))
if cont_or_exit in ['Main', 'main', 'MAIN']:
main()
elif cont_or_exit in ['Again', 'again', 'AGAIN']:
x = True
elif cont_or_exit in ['Exit', 'exit', 'EXIT']:
x = False
exit()

def main():
select = input('Type in 1 for IP address info OR Type in 2 for IP Port Info: ')
if select == '1':
shodan_ip_info()
if select == '2':
shodan_port_info()
else:
print('Did not select an option')
exit()

main()

Morty Proxy This is a proxified and sanitized view of the page, visit original site.