Created
June 8, 2024 17:30
-
-
Save rxerium/658991f0ae2aed334ebeabb99cf6fb7f to your computer and use it in GitHub Desktop.
Shodan Script to export all products that are run on common web ports
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
import shodan | |
# Your Shodan API key | |
api_key = 'YOUR_SHODAN_API_KEY' | |
# Initialize the Shodan API | |
api = shodan.Shodan(api_key) | |
# Search queries for common web ports | |
queries = [ | |
'port:80', 'port:443', 'port:8080', 'port:8443', 'port:8000', 'port:8888', | |
'port:81', 'port:4443', 'port:3000', 'port:5000', 'port:7000', 'port:9090', 'port:9443' | |
] | |
# File to output the results | |
output_file = 'shodan_products_common_web_ports.txt' | |
# Set to store unique products | |
unique_products = set() | |
try: | |
# Perform the searches for each port | |
for query in queries: | |
page = 1 | |
while True: | |
# Perform the search with pagination | |
results = api.search(query, page=page) | |
# Collect all unique products | |
for result in results['matches']: | |
product = result.get('product') | |
if product: | |
unique_products.add(product) | |
# Check if there are more results | |
if (page * len(results['matches'])) >= results['total']: | |
break | |
page += 1 | |
# Write the unique products to a file | |
with open(output_file, 'w') as file: | |
for product in unique_products: | |
file.write(f'{product}\n') | |
print(f'Products successfully written to {output_file}') | |
except shodan.APIError as e: | |
print(f'Error: {e}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment