Skip to content

Instantly share code, notes, and snippets.

@azet
Created May 13, 2015 16:43
Show Gist options
  • Select an option

  • Save azet/0bbae876f75a48c87265 to your computer and use it in GitHub Desktop.

Select an option

Save azet/0bbae876f75a48c87265 to your computer and use it in GitHub Desktop.
get a SPF record based on an IP address, if possible
#!/usr/bin/env bash
#
# checks if a SPF record is present for a given IP
# if that IP resolves for the MX and is used without
# redirects/load balacing etc.
#
# needs to be improved
#
readonly IP=${1}
function get_pointer() {
local pointer=$(dig -x "${IP}" +short)
printf "%s\n" ${pointer%.}
}
function main() {
local pointer=$(get_pointer)
[[ -z ${pointer} ]] && return 1
local txt=$(dig TXT "${pointer}" +short)
[[ ${txt} =~ "spf" ]] || return 1
echo ${txt}
}
main
#EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment