spf_check/spf_check.sh
2023-11-24 10:05:33 +00:00

33 lines
975 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
usage() {
echo "Usage: $(basename $0) {domain.tld} {debug} | debug is optional, accepts true/yes/1 for true and false/no/0 for false (or just don't use)"
exit 1
}
[[ $# -gt 0 ]] && DOMAIN=$1 || usage
case $2 in
[yY][eE][sS]|[tT][rR][uU][eE]|1) DEBUG=true;;
esac
COUNT=0;DEPTH=0;mDEPTH=0;INDENT=2;
checkIncludes() {
SPF=$1
for I in $(dig -t txt $SPF +short|grep -oE "include:.* |ip[4,6]:.* "|sed 's/include://g; s/ip[4,6]://g; s/\"//g'|tr ' ' '\n'); do
[[ $DEBUG ]] && printf "%*s%s %s\n" $(($DEPTH*$INDENT)) '' "$I"
if [[ ! ${I} =~ ^[0-9] ]]; then
DEPTH=$(($DEPTH+1))
mDEPTH=$(($mDEPTH+1))
checkIncludes $I
fi
COUNT=$(($COUNT+1))
done
DEPTH=$(($DEPTH-1))
}
checkIncludes $DOMAIN
[[ $DEBUG ]] && echo
GRN="";YEL="";RED="";NOCOL="";
case $mDEPTH in
[1-7]) SCOL="${GRN}";;
[8-9]) SCOL="${YEL}";;
*) SCOL="${RED}";;
esac
echo "${SCOL}Total: $COUNT (Max lookups: $mDEPTH)${NOCOL}"