4 ms·
$ 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
by pdkl95 6y ago
$ 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
- opsunit 6y agoI have a tool that makes parsing that file easier for some query types: https://github.com/sampointer/digaws https://github.com/sampointer/digaws
- throw0101a 6y agoYou 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/ https://stedolan.github.io/jq/
- npteljes 6y agoI love jq. The simple usecase of piping a json to "jq .", having it pretty-printed is awesome in itself.
- geek_at 6y agoalso someone tell them about curl
- throw0101a 6y agoI 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.
- tempest_ 6y agoWith jq and curl curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes | .[].ip_prefix | .[-3:]' | sort | uniq -c
- xorcist 6y ago".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!
- samoa42 6y agohow does jq solve the problem more elegant/shorter/readable/portable?