Last active
January 15, 2018 09:33
-
-
Save ionred/e689a2192759f25075d16bfad84aa622 to your computer and use it in GitHub Desktop.
Gets Amazon & Netflix IP's to route traffic through a specific gateway to bypass VPN (Creates windows route add statement by default)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gatewayip=192.168.2.1 | |
rm routeListtemp > /dev/null 2>&1 | |
rm amazonCIDR > /dev/null 2>&1 | |
rm routeList > /dev/null 2>&1 | |
rm netflixip > /dev/null 2>&1 | |
rm netflixCIDR > /dev/null 2>&1 | |
rm arinunclean > /dev/null 2>&1 | |
rm arinCIDR > /dev/null 2>&1 | |
#cycle 3 times to make sure we get a good set of A records, Amazon ELB (Netflix host) only gives 8 a records per lookup | |
echo -en "Getting Netflix IP's from DNS Lookups...\t\t\t\t\t" | |
dig +short nflximg.net > netflixip | |
dig +short netflix.com >> netflixip | |
dig +short nflxext.com >> netflixip | |
dig +short nflxvideo.net >> netflixip | |
dig +short nflximg.net >> netflixip | |
dig +short netflix.com >> netflixip | |
dig +short nflxext.com >> netflixip | |
dig +short nflxvideo.net >> netflixip | |
dig +short nflximg.net >> netflixip | |
dig +short netflix.com >> netflixip | |
dig +short nflxext.com >> netflixip | |
dig +short nflxvideo.net >> netflixip | |
tput hpa 80; echo "DONE!" | |
echo -en "Done getting Netflix IP's from DNS. Starting whois for IP range information..." | |
#remove duplicates | |
sort -u netflixip -o netflixCIDR | |
#As these are random IP's we need to acquire the blocks. utilize WHOIS to get CIDR information | |
while read filename; do whois "$filename" | grep CIDR | cut -c 17- >> netflixCIDR; done < netflixip | |
tput hpa 80; echo "DONE!" | |
echo -en "Breaking multilines and sorting..." | |
#remove non CIDR results | |
sed -i '/\//!d' netflixCIDR | |
#break multiple CIDRs on one line into multiple lines | |
sed -i 's/, /\n/g' netflixCIDR | |
sort -u netflixCIDR -o netflixCIDR | |
rm netflixip | |
tput hpa 80; echo "DONE!" | |
echo -en "Getting Netflix ARIN Ranges..." | |
#DNS found IPs arent enough, but the streaming servers are not found under specific dns names, they are geographic and dynamic, so utilize ARIN get list a list of IPs assigned to Netflix Streaming Services | |
curl -O -H "Accept: application/json" http://whois.arin.net/rest/org/SS-144/nets > /dev/null 2>&1 | |
#parse json | |
jq -r '.nets.netRef | map([."@startAddress", ."@endAddress"] | join("-")) | join ("\n")' nets > arinunclean | |
tput hpa 80; echo "DONE!" | |
echo -en "Cleaning list and getting CIDR..." | |
rm nets | |
#Remove IPV6 addresses | |
sed -i '/::/d' ./arinunclean | |
cat arinunclean | xargs -L1 ipcalc > arinCIDR | |
rm arinunclean | |
sed -i '/deagg/d' ./arinCIDR | |
tput hpa 80; echo "DONE!" | |
echo -en "Starting Amazon AWS IP range download..." | |
curl -O https://ip-ranges.amazonaws.com/ip-ranges.json -s | |
jq -r '.prefixes | .[].ip_prefix' < ip-ranges.json > amazonCIDR | |
tput hpa 80; echo "DONE!" | |
echo -en "Converting each list to netmask format..." | |
rm ip-ranges.json | |
echo "::NetflixDNS" > routeListtemp; while IFS="/" read IP S; do | |
M=$(( 0xffffffff ^ ((1 << (32-S)) -1) )); echo "route ADD $IP MASK $(( (M>>24) & 0xff )).$(( (M>>16) & 0xff )).$(( (M>>8) & 0xff )).$(( M & 0xff )) $gatewayip METRIC 1"; done < netflixCIDR >> routeListtemp | |
echo "::Amazon" >> routeListtemp; while IFS="/" read IP S; do | |
M=$(( 0xffffffff ^ ((1 << (32-S)) -1) )); echo "route ADD $IP MASK $(( (M>>24) & 0xff )).$(( (M>>16) & 0xff )).$(( (M>>8) & 0xff )).$(( M & 0xff )) $gatewayip METRIC 1"; done < amazonCIDR >> routeListtemp | |
echo "::NetflixStreamingARIN" >> routeListtemp; while IFS="/" read IP S; do | |
M=$(( 0xffffffff ^ ((1 << (32-S)) -1) )); echo "route ADD $IP MASK $(( (M>>24) & 0xff )).$(( (M>>16) & 0xff )).$(( (M>>8) & 0xff )).$(( M & 0xff )) $gatewayip METRIC 1"; done < arinCIDR >> routeListtemp | |
rm netflixCIDR | |
rm amazonCIDR | |
rm arinCIDR | |
tput hpa 80; echo "DONE!" | |
echo -en "Removing duplicates..." | |
awk '!x[$0]++' routeListtemp > routelist | |
tput hpa 80; echo "DONE!" | |
echo -en "Script Complete. Counting files in routelist." | |
tput hpa 80; echo "$(wc -l routelist | cut -d ' ' -f 1)" | |
rm routeListtemp | |
while true; do | |
echo -en "\n\nEnter D to display list, or anything else to exit: \t\t\t\t" | |
read input | |
if [[ $input = 'd' ]] || [[ $input = 'D' ]] | |
then | |
cat routelist | |
break | |
else | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment