Skip to content

Instantly share code, notes, and snippets.

@darron
Created January 5, 2015 23:19
Show Gist options
  • Save darron/811cf41a6ec3dbfcb97a to your computer and use it in GitHub Desktop.
Save darron/811cf41a6ec3dbfcb97a to your computer and use it in GitHub Desktop.
Get IP Ranges from EC2
#!/bin/bash
# You need: curl, jq, and ipcalc to run this.
# You should already have cut, sort and uniq if you're on OS X or Linux.
RANGES=$(curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq .prefixes | jq '.[] | select(.region=="us-east-1")' | jq 'select(.service=="EC2")' | jq .ip_prefix | cut -d '"' -f 2 | sort | uniq)
for range in $RANGES
do
MIN=$(ipcalc -bn $range | grep "HostMin" | cut -d ':' -f 2)
MAX=$(ipcalc -bn $range | grep "HostMax" | cut -d ':' -f 2)
echo "$range (${MIN// /} - ${MAX// /})"
done
@oviliz
Copy link

oviliz commented Apr 18, 2016

sh ./gistfile1.sh
./gistfile1.sh: 12: ./gistfile1.sh: Bad substitution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment