giladh

MX Record Checker

Jul 6th, 2011
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.63 KB | None | 0 0
  1. #!/bin/bash -e
  2. #
  3. # Created by Gilad Halevy 5/3/11 to check MX records
  4.  
  5.  
  6. # Check for command line arguments, otherwise set domain list statically
  7. if [[ "$#" != "0" ]]; then
  8.   domains="$@"
  9. else
  10.   domains=("2kgames.com" "2ksports.com" "take2international.com" "vcentertainment.com" "2kaustralia.com" "2kaustralia.com.au" "irrational.com.au" "irrationalgames.com" "irrationalgames.com.au" "2kboston.com" "2klosangeles.com" "kushgames.com" "beaterator.com" "rockfoo.com" "rockstar.com" "rockstarlondon.com" "globalstarsoftware.com" "rockstargames.com" "rockstarleeds.com" "rockstartoronto.com" "rockstarvancouver.com" "take2games.com" "irrationalstudios.com" "2kmarin.com" "libertycitypolice.com" "rockstarnewengland.com" "maddocsoftware.com" "firaxis.com" "rockstarlincoln.com" "take2espana.com" "take2europe.com" "rockstarsd.com" "rockstarsandiego.com" "take2asia.com" "catdaddy.com" "catdaddygames.com" "powerstationrecall.com" "taketwo.fr joagcanada.com" "irrationalboston.com" "jackofallgames.com" "take2.de" "gouranga.com" "take2interactive.com.au" "2kgames.com.au" "2ksports.com.au" "take2benelux.com" "2kczech.com" "2kczech.cz" "illusionsoftworks.com" "illusionsoftworks.cz" "illusionsoftworks.eu" "is.cz" "mafia-game.com" "mafia-game.cz" "rockstarnorth.com" "rockstarnorth.co.uk" "2k.com" "take2.it" "2kchina.com" "2kgames.cn")
  11. fi
  12.  
  13. ERRORFILE=/tmp/mxcheck_errors
  14. if [[ -f "$ERRORFILE" ]]; then
  15.   rm "$ERRORFILE"
  16. fi
  17.  
  18. # set variables
  19. setvars () {
  20.   mx="$(dig "$domain" MX | grep -s -e "$domain" -e MX | tail -2 | sort -k3n)" # get just the MX records, place them in a var
  21.   mx1="$(echo "$mx" | head -1 | awk '{ printf ("%-25s%-15s%-15s%-25s", $1, $2, $5, $6) }')" # print fancy fields for mx1
  22.   mx2="$(echo "$mx" | tail -1 | awk '{ printf ("%-25s%-15s%-15s%-25s", $1, $2, $5, $6) }')" # print fancy fields for mx2
  23.   mx1Aip="$(dig $(echo "$mx1" | awk '{ print $4 }') A +short)" # dig for the IP for mx1
  24.   mx2Aip="$(dig $(echo "$mx2" | awk '{ print $4 }') A +short)" # dig for the IP for mx2
  25.   }
  26.  
  27. for domain in ${domains[@]}; do
  28.   setvars # call setvars
  29.   if [[ "$mx2" =~ ^"$domain" ]]; then # Check via regex if MX records exist
  30.     printf "%-25s%-15s%-15s%-25s%-20s\n" "DOMAIN" "TTL" "PRIORITY" "RECORD" "IP"
  31.     printf "%-25s%-15s%-15s%-25s%-20s\n" "------" "---" "--------" "------" "--"
  32.     echo -e "$mx1""$mx1Aip"
  33.     echo -e "$mx2""$mx2Aip\n"
  34.   else # records do not exist
  35.     echo "WARNING - MISSING MX RECORDS FOR DOMAIN ${domain}!" 1>>"$ERRORFILE" # output errors to tmp file
  36.   fi
  37. done
  38.  
  39. # Print errors
  40. if [[ -s $ERRORFILE ]]; then
  41.   cat "$ERRORFILE" && rm "$ERRORFILE" # print contents of error file to STDOUT, then discard it
  42. fi
  43.  
  44. exit
Advertisement
Add Comment
Please, Sign In to add comment