Created
March 5, 2020 23:57
-
-
Save rogueresistor/92d1a6992951ed8391a56f080a39b3a3 to your computer and use it in GitHub Desktop.
List all of the GCP IP ranges
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
#!/bin/sh | |
# This is modified from the script posted at | |
# https://cloud.google.com/compute/docs/faq#where_can_i_find_product_name_short_ip_ranges, | |
# this will also show the IPv6 ranges that are returned | |
set -- $(dig -t txt +short _cloud-netblocks.googleusercontent.com) | |
included="" ip4="" | |
while [ $# -gt 0 ]; do | |
k="${1%%:*}" v="${1#*:}" | |
case "$k" in | |
include) | |
# only include once | |
if [ "${included% $v *}" = "${included}" ]; then | |
set -- "$@" $(dig -t txt +short "$v") | |
included=" $v $included" | |
fi | |
;; | |
ip4) ip4="$v $ip4" ;; | |
ip6) ip6="$v $ip6" ;; | |
esac | |
shift | |
done | |
echo -n "Today's date: " | |
date | |
echo "" | |
echo "GCP IPv4 ranges:" | |
(for i in $ip4; do | |
echo "$i" | |
done) | sort -n | |
echo "" | |
echo "GCP IPv6 ranges: " | |
for i in $ip6; do | |
echo "$i" | |
done |
Author
rogueresistor
commented
Mar 5, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment