Skip to content

Instantly share code, notes, and snippets.

@brianwhigham
Created May 24, 2016 17:12
Show Gist options
  • Save brianwhigham/bfe1d9b0d50b6a3c24a53b21aaa453b8 to your computer and use it in GitHub Desktop.
Save brianwhigham/bfe1d9b0d50b6a3c24a53b21aaa453b8 to your computer and use it in GitHub Desktop.
Use my awsiprangefilter.py (https://gist.github.com/brianwhigham/d3d74c17c423254db2ba973f97fae614) gist to list AWS IP ranges. Then, use ipcalc to count how many hosts are in that list.
#!/bin/sh
# usage: supply a comma-separated list of regions as the first argument
# and a comma-separated list of services as the second argument.
wget -O /tmp/ip-ranges.json https://ip-ranges.amazonaws.com/ip-ranges.json
unset hostcnt
unset tcnt
for r in $(awsiprangefilter.py -r $1 --services $2)
do
hostcnt=$(ipcalc $r|grep Hosts|cut -d " " -f 2)
let tcnt+=$hostcnt
done
echo $tcnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment