-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspf_check.sh
executable file
·32 lines (32 loc) · 975 Bytes
/
spf_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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="[1;32m";YEL="[1;33m";RED="[1;31m";NOCOL="[0m";
case $mDEPTH in
[0-7]) SCOL="${GRN}";;
[8-9]) SCOL="${YEL}";;
*) SCOL="${RED}";;
esac
echo "${SCOL}Total: $COUNT (Max lookups: $mDEPTH)${NOCOL}"