Skip to content

Instantly share code, notes, and snippets.

@Murthysagi
Forked from githubutilities/SPF-records.md
Created December 5, 2016 11:49
Show Gist options
  • Save Murthysagi/6799f83968ac86e261dedf24b3d04225 to your computer and use it in GitHub Desktop.
Save Murthysagi/6799f83968ac86e261dedf24b3d04225 to your computer and use it in GitHub Desktop.
SPF Records

SPF Records

Sender Policy Framework (SPF) is an email validation system designed to prevent spam by detecting email spoofing.

# get spf record domain from google
dig TXT +short google.com

# get spf record from google
dig @8.8.8.8 TXT +short _spf.google.com

# get part of google ip ranges
dig TXT +short _netblocks.google.com

# beautify the results
dig TXT +short _netblocks{,2,3}.google.com | tr ' ' '\n' | grep '^ip4:'

# script for counting ips of google
total=0
for slash in $(dig TXT +short _netblocks{,2,3}.google.com | tr ' ' '\n' | grep '^ip4:' | cut -d '/' -f 2); do
  total=$((total+$(echo "2^(32-$slash)" | bc -l)))
done
echo $total

# script for counting ips of baidu
total=0
for slash in $(dig TXT +short spf{,2,3}.baidu.com | tr ' ' '\n' | grep '^ip4:' | cut -d '/' -f 2); do
  if [[ $slash =~ ^ip+ ]] ; then
    total=$((total+1))
  else
    total=$((total+$(echo "2^(32-$slash)" | bc -l)))
  fi
done
echo $total

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment