-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshodan_search.py
26 lines (19 loc) · 975 Bytes
/
shodan_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import shodan
import csv
api_key = "YOUR_API_KEY"
api = shodan.Shodan(api_key)
# Get user input for the search query
query = input("Enter your search query: ")
try:
# Search for the user-specified query
results = api.search(query)
# Open a CSV file for writing the results
with open('search_results.csv', mode='w') as csv_file:
fieldnames = ['IP', 'Port', 'Organization', 'Operating System', 'Hostnames', 'Data']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
for result in results['matches']:
writer.writerow({'IP': result['ip_str'], 'Port': result['port'], 'Organization': result.get('org', 'N/A'), 'Operating System': result.get('os', 'N/A'), 'Hostnames': result.get('hostnames', 'N/A'), 'Data': result.get('data', 'N/A')})
print("Results found: {} and saved in search_results.csv".format(results['total']))
except shodan.APIError as e:
print("Error: {}".format(e))