Skip to content

Instantly share code, notes, and snippets.

@menzow
Created October 13, 2018 02:53
Show Gist options
  • Save menzow/71e129925252dcf0091df747fa79019a to your computer and use it in GitHub Desktop.
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.
#!/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