Skip to content

Instantly share code, notes, and snippets.

@jjsantanna
Last active July 21, 2019 22:23
Show Gist options
  • Save jjsantanna/c73220ed6db135a309b1ec356b71221d to your computer and use it in GitHub Desktop.
Save jjsantanna/c73220ed6db135a309b1ec356b71221d to your computer and use it in GitHub Desktop.
usage of jp on a json.gz file
gzcat raw-daily-2019-07-17.json.gz |jq "{data, ip_str, port, location, asn}" -n > shodan_20190717_lessfields.json
cat shodan.json | jq -r '. | {ip: .ip_str, port: .port, cc: .location.country_code3, data: .data} | @json' > /tmp/shodan1.txt
-----------
shodan_raw_filename='shodan_output.json.gz'
import json
import gzip
outputfile_name = shodan_raw_filename.split('.')[0]+'_simplified.json'
outputfile = open(outputfile_name, 'w')
data=[]
for line in gzip.open(shodan_raw_filename, 'r'):
loaded_line = json.loads(line)
json.dump({'ip':loaded_line['ip_str'],
'port':loaded_line['port'],
'cc': loaded_line['location']['country_code3'],
'data': loaded_line['data']}, outputfile)
outputfile.write("\n")
outputfile.close()
!gzip $outputfile_name -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment