Skip to content

Instantly share code, notes, and snippets.

@suominen
Last active November 5, 2020 12:22
Show Gist options
  • Save suominen/c4c2b8219388711088ffc053250d7daf to your computer and use it in GitHub Desktop.
Save suominen/c4c2b8219388711088ffc053250d7daf to your computer and use it in GitHub Desktop.
List Google's outbound SMTP server address blocks
#!/bin/sh
set -eu
listblocks()
{
local i
for i in $(dig +short "${1}" txt)
do
r="$(echo "${i}" | tr -d ' "')"
case "${r}" in
v=spf1|[-?~]all|'')
;;
include:*)
listblocks "${r#include:}"
;;
ip[46]:*)
printf "%s\n" "${r#ip[46]:}"
;;
a:*)
dig +short "${r#a:}" a
dig +short "${r#a:}" aaaa
;;
#mx:*)
# ;;
*)
printf "# %s\n" "${r}"
;;
esac
done
}
if [ ${#} -lt 1 ]
then
set -- _spf.google.com
fi
for block
do
echo "# ${block}"
listblocks "${block}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment