Extracting some strings with jq from Rapid7 OpenData website

Viewed 93

I was wondering if someone had an idea how to extract with 'jq' the following strings; 'ip, port' from the input files available on Rapid7 opendata website:

Rapid7 OpenData website

Any help would be very appreciated,

Thanks

1 Answers

Download the JSON from Rapid7 OpenData

$ wget https://opendata.rapid7.com/sonar.https/2020-07-26-1595771130-https_get_50880.json.gz

Extract 'ip' and 'port' fields

$ zcat 2020-07-26-1595771130-https_get_50880.json.gz | jq '.ip,.port' | head
"73.71.198.224"
50880
"3.228.14.207"
50880
"175.139.245.229"
50880
"162.208.16.163"
50880
"58.58.213.88"
50880

Extract fields in the form 'ip:port'

zcat 2020-07-26-1595771130-https_get_50880.json.gz | jq -r '"\(.ip):\(.port)"' | head
73.71.198.224:50880
3.228.14.207:50880
175.139.245.229:50880
162.208.16.163:50880
58.58.213.88:50880
18.130.113.90:50880
54.216.22.17:50880
15.236.60.123:50880
77.54.234.109:50880
71.37.173.187:50880

Thanks to @peak for the improvement!

Related