Skip to content

Instantly share code, notes, and snippets.

@omar-yassin
Last active October 28, 2019 19:35
Show Gist options
  • Save omar-yassin/9956416 to your computer and use it in GitHub Desktop.
Save omar-yassin/9956416 to your computer and use it in GitHub Desktop.
DNS SPF Expander (MAX LOOKUP should not exceed 10 lookups)
#!/bin/bash
#TO RUN
# > ./dns_spf_expander.sh domain.com
lookup_count=0
function spf_expand {
for spf in $1 ; do
if echo $spf | grep "include:" > /dev/null 2>&1 ; then
((lookup_count++))
temp_spf=`echo $spf | awk -F"include:" '{print $2}'`
temp_results=`/usr/bin/nslookup -q=TXT "$temp_spf" 8.8.8.8 | grep text`
echo "Lookup $lookup_count: $temp_spf"
if echo $temp_results | grep "include:" > /dev/null 2>&1 ; then
spf_expand "${temp_results}"
fi
fi
done
}
lookup_spf=`dig txt $1 | grep "v=spf1" | awk -F"\"" '{print $2}'`
echo "$1 SPF record is \"$lookup_spf\""
spf_expand "${lookup_spf}"
echo "SPF DNS LOOOKUP Count = $lookup_count"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment