SOA Checker

Page content

Intro

this is a little script which reads the Name Servers for a given Domain, and then asks the NameServer for the SOA of this Domain.

Script

cat << 'EOFx' > soachecker.sh
#!/usr/bin/env bash

# Little SOA & Serial Checker, v0.2, @stoege

tmpfile=$(mktemp)

# Check Args
echo
if [ $# -eq 0 ]; then
  d="stoege.net"
  echo -e "No argument provided. use \033[1m'${d}'\033[0m"

  cat <<EOF

----------------------- EXAMPLE ----------------------
soachecker.sh stoege.net
soachecker.sh 214.69.159.in-addr.arpa
soachecker.sh 7.f.f.f.c.0.c.0.8.f.4.0.1.0.a.2.ip6.arpa
------------------------------------------------------
EOF

elif [ $# -eq 1 ]; then
  d="$1"
  echo -e "Domain \033[1m'${d}'\033[0m provided"
else
  echo -e "\033[1mmore than one arguments provided. Exit 1.\033[0m"
  exit 1
fi

# Build File
for i in $(dig +short NS ${d} |tr '\n' ' '); do
  echo -e "\ndig +short SOA \033[1m@${i}\033[0m ${d}"
  dig +short SOA @${i} ${d} |tee -a ${tmpfile}
done

# uniq & count
lines=$(sort -u "${tmpfile}" |wc -l)
echo

# Check the count and output the result
if [[ $lines -ne 1 ]]; then
cat <<EOF

********************
*****  ALERT   *****
********************

EOF
fi

cat ${tmpfile} |sort |uniq -c |awk '{ printf "%d x Serial: %s\n", $1,$4 }'

# cleanup
rm ${tmpfile}

echo
exit 0
EOFx

chmod u+x soachecker.sh

Run it

$ ./soachecker.sh stoege.net

Domain 'stoege.net' provided

dig +short SOA @ns1.noflow.ch. stoege.net
ns1.noflow.ch. hostmaster.noflow.ch. 2025010708 3600 900 1209600 1800

dig +short SOA @ns3.noflow.ch. stoege.net
ns1.noflow.ch. hostmaster.noflow.ch. 2025010708 3600 900 1209600 1800

dig +short SOA @ns2.nolink.ch. stoege.net
ns1.noflow.ch. hostmaster.noflow.ch. 2025010708 3600 900 1209600 1800

3 x Serial: 2025010708

let me know if you like this !


Any Comments ?

sha256: 642d4c3c2128576dfefa90a829147bc4a1640206bf5de9d828f7a36bc91a32ea