Skip to content

Instantly share code, notes, and snippets.

@hosni
Forked from n0531m/list_gcp_iprange.sh
Created March 30, 2023 22:24
Show Gist options
  • Save hosni/12038e450da58ca6e11e1125a93023db to your computer and use it in GitHub Desktop.
Save hosni/12038e450da58ca6e11e1125a93023db to your computer and use it in GitHub Desktop.
Google Cloud Platform : ip address range
#!/bin/bash
# https://cloud.google.com/compute/docs/faq#find_ip_range
# nslookup -q=TXT _cloud-netblocks.googleusercontent.com 8.8.8.8
myarray=()
for LINE in `dig txt _cloud-netblocks.googleusercontent.com +short | tr " " "\n" | grep include | cut -f 2 -d :`
do
myarray+=($LINE)
for LINE2 in `dig txt $LINE +short | tr " " "\n" | grep include | cut -f 2 -d :`
do
myarray+=($LINE2)
done
done
for LINE in ${myarray[@]}
do
dig txt $LINE +short | tr " " "\n"
done | grep ip4 | cut -f 2 -d : | sort -n +0 +1 +2 +3 -t .
# changing target to _spf.google.com, you can get a simliar range now for Google Apps mail servers.
# https://support.google.com/a/answer/60764
# changing it to _netblocks.google.com will help get all the ip ranges google uses for its services.
@hosni
Copy link
Author

hosni commented Apr 4, 2023

curl --silent https://www.gstatic.com/ipranges/cloud.json | jq '.prefixes[] | .ipv4Prefix // .ipv6Prefix' -r | sort -r > /root/Documents/google-cloud-ips.txt

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