Skip to content

Instantly share code, notes, and snippets.

@byt3bl33d3r
Created November 10, 2015 21:43
Show Gist options
  • Save byt3bl33d3r/c3919985888ef3834342 to your computer and use it in GitHub Desktop.
Save byt3bl33d3r/c3919985888ef3834342 to your computer and use it in GitHub Desktop.
Get up hosts using Shodan! Takes as input a comma separated subnet list
import shodan
import sys
from shodan import APIError
from netaddr import IPNetwork
SHODAN_API_KEY= 'APIKEY'
api = shodan.Shodan(SHODAN_API_KEY)
targets = map(IPNetwork, sys.argv[1].split(','))
hosts = []
for net in targets:
for target in net.iter_hosts():
hosts.append(str(target))
for host in hosts:
try:
res = api.host(host)
print host
except (APIError, KeyboardInterrupt):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment