News for hackers. Stuff that matters.
Re:Amazon owns more than $2B worth of IPv4 addresses by pdkl95 on Saturday December 12, 2020 @02:38AM (#25396481)

  $ wget https://ip-ranges.amazonaws.com/ip-ranges.json
  $ grep ip_prefix ip-ranges.json |
    sed -re 's|.*(/[0-9]+).*|\1|' |
    sort | uniq -c

      4 /11
     16 /12
     30 /13
     82 /14
    188 /15
    278 /16
     70 /17
     63 /18
     30 /19
     47 /20
    111 /21
    248 /22
    204 /23
    839 /24
     68 /25
    235 /26
    142 /27
    124 /28
     50 /29
     42 /30
    362 /31
    370 /32
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.
Re:Amazon owns more than $2B worth of IPv4 addresses by opsunit on Saturday December 12, 2020 @04:37AM (#25397048)
I have a tool that makes parsing that file easier for some query types: https://github.com/sampointer/digaws