#!/usr/bin/env python # # export_hosts.py # import gzip import shodan import simplejson import sys # Setup the Shodan API YOUR_API_KEY = "..." api = shodan.Shodan(YOUR_API_KEY) # Load the records for line in gzip.open(sys.argv[1], 'r'): # Decode the line into a banner banner = simplejson.loads(line) # Grab the full host information for an IP if 'ipv6' in banner: host = api.host(banner['ipv6']) else: host = api.host(banner['ip_str']) # Serialize the host information into a JSON string print(simplejson.dumps(host))