Skip to content

Instantly share code, notes, and snippets.

@ahwayakchih
Created April 23, 2020 08:06
Show Gist options
  • Save ahwayakchih/26fca8968c806cfe6e9e59617da3f1a2 to your computer and use it in GitHub Desktop.
Save ahwayakchih/26fca8968c806cfe6e9e59617da3f1a2 to your computer and use it in GitHub Desktop.
Get IP4s of Google's servers' to, for example, whitelist them for accessing own services
#!/bin/sh -e
get_ip4s () {
dig +short txt $1 | grep -Eo '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[1-2][0-9]|[1-9])?)?' | tr '\n' ','
}
echo -n $(get_ip4s _netblocks.google.com)
# `_netblocks2.google.com` returns only IPv6 addresses, so we can skip it
#echo -n $(get_ip4s _netblocks2.google.com)
echo -n $(get_ip4s _netblocks3.google.com)
echo -n $(get_ip4s _netblocks4.google.com)
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment