Created
December 9, 2015 02:26
-
-
Save achillean/65285db312cf7614bc9c to your computer and use it in GitHub Desktop.
Read a Shodan JSON file and print out the full host information.
This file contains hidden or 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
#!/usr/bin/env python | |
# | |
# export_hosts.py <export.json.gz> | |
# | |
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run the script save as "export-hosts.py" and fill in the "YOUR_API_KEY" variable with your own Shodan API key. Then run the script using:
Where export.json.gz is an JSON export generated from the website or with the shodan command-line utility.