Skip to content

Instantly share code, notes, and snippets.

@0xded093
Created June 22, 2016 08:40
Show Gist options
  • Save 0xded093/c5d9d213920e35f3ef9c6b5b32b5a8e9 to your computer and use it in GitHub Desktop.
Save 0xded093/c5d9d213920e35f3ef9c6b5b32b5a8e9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import shodan
import sys
# Configuration
API_KEY = "apikey"
# Input validation
if len(sys.argv) == 1:
print 'Usage: %s <search query>' % sys.argv[0]
sys.exit(1)
try:
# Setup the api
api = shodan.Shodan(API_KEY)
# Perform the search
query = ' '.join(sys.argv[1:])
result = api.search(query)
# Loop through the matches and print each IP
for service in result['matches']:
print service['ip_str']+' - '+ str(service['port'])
print '---------------------------------------------------'
print service['data']
print '---------------------------------------------------'
except Exception as e:
print 'Error: %s' % e
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment