Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Created January 6, 2016 06:25
Show Gist options
  • Save githubutilities/cf34b78ff371504905aa to your computer and use it in GitHub Desktop.
Save githubutilities/cf34b78ff371504905aa 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