Created
October 13, 2018 02:53
-
-
Save menzow/71e129925252dcf0091df747fa79019a to your computer and use it in GitHub Desktop.
Recursively fetch all google cloud platform (gcp) ip address ranges. Outputs both ipv4 and ipv6 ranges in parsable format.
This file contains hidden or 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
#!/bin/bash | |
netblocks=$(dig @8.8.8.8 txt _cloud-netblocks.googleusercontent.com +short | grep -Eo '_cloud\S+') | |
function get_netblock_ips { | |
response=$(dig @8.8.8.8 txt +short "$1") | |
for block in $(echo "$response" | grep -Eo 'include:\S+' | cut -d: -f2 ); do | |
get_netblock_ips "$block" | |
done | |
echo "$response" | grep -Eo 'ip[46]:\S+' | cut -d: -f2- | |
} | |
{ for block in $netblocks; do get_netblock_ips "$block"; done } | sort -n | uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment