News for hackers. Stuff that matters.
Re:Amazon owns more than $2B worth of IPv4 addresses by throw0101a on Saturday December 12, 2020 @09:20AM (#25398359)
You may be interested in jq:

> jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

* https://stedolan.github.io/jq/

Re:Amazon owns more than $2B worth of IPv4 addresses by tempest_ on Saturday December 12, 2020 @12:12PM (#25399730)
With jq and curl

  curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes | .[].ip_prefix | .[-3:]' |  sort | uniq -c
Re:Amazon owns more than $2B worth of IPv4 addresses by xorcist on Saturday December 12, 2020 @03:05PM (#25401166)
".a | .b" is just ".a.b" in jq.

Netmasks might not always be three characters.

Perhaps something like this:

  curl -sf https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | grep -o '/.*' | sort | uniq -c
If you really wanted to, you could even do the splitting and counting in jq:

  curl -sf https://ip-ranges.amazonaws.com/ip-ranges.json | jq 'reduce (.prefixes[].ip_prefix | split("/")[1]) as $mask ({}; .[$mask] += 1)'
It's a super handy tool with a real language in there!
Re:Amazon owns more than $2B worth of IPv4 addresses by npteljes on Saturday December 12, 2020 @09:49AM (#25398528)
I love jq. The simple usecase of piping a json to "jq .", having it pretty-printed is awesome in itself.
Re:Amazon owns more than $2B worth of IPv4 addresses by samoa42 on Monday December 14, 2020 @04:14AM (#25414952)
how does jq solve the problem more elegant/shorter/readable/portable?
Re:Amazon owns more than $2B worth of IPv4 addresses by geek_at on Saturday December 12, 2020 @11:31AM (#25399334)
also someone tell them about curl
Re:Amazon owns more than $2B worth of IPv4 addresses by throw0101a on Saturday December 12, 2020 @03:36PM (#25401472)
I default to wget because as a sysadmin I usually want to download a file, and that is the default behaviour. Perhaps devs default to curl because they want to pipe things.