Sysadmin > SolarIs > AnycastDNS > DnsTestScript
#!/bin/sh
# awfull hacked script
# a modification of the check_soa script from the book "dns and bind"
#
if test "$1" = ""
then
    echo usage: $0 server
    exit 1
fi
SERVER=$1
#
# Use nslookup to discover the name servers for this zone ($1).
#
# put here you names and ip you like to test
# or modify the script, that you can use an external file

   cat > /tmp/testlookups.$$ <<-LOOKUPS
        panama.xyz.de
        xyz.de
        blafasel.de
        192.168.111.48
LOOKUPS

# Use awk to grab the name server's domain names from the nameserver lines.
# (The names are always in the last field.)  Use sort -u to weed out
# duplicates; we don't actually care about collation.
#
LOOKUPS=`cat /tmp/testlookups.$$`
if test "$LOOKUPS" = ""
then
    #
    # Didn't find any servers.  Just quit silently; nslookup will
    # have detected this error and printed a message.  That will
    # suffice.
    #
    exit 1
fi
#
# Check each server's SOA serial number.  The output from
# nslookup is saved in two temp files: nso.$$ (standard output)
# and nse.$$ (standard error).  These files are rewritten on
# every iteration.  Turn off defname and search since we
# should be dealing with fully qualified domain names.
#
# NOTE: this loop is rather long; don't be fooled.
#
for i in $LOOKUPS
do
  nslookup >/tmp/nso.$$ 2>/tmp/nse.$$ <<-EOF
    server $SERVER
    set norecurse
    $i
EOF
  #
  # Does this response indicate that the current server ($i) is
  # authoritative?  The server is NOT authoritative if (a) the
  # response says so, or (b) the response tells you to find
  # authoritative info elsewhere.
  #
  if egrep "Non-authoritative|Authoritative answers can be" \
                                          /tmp/nso.$$ >/dev/null
  then
    echo $i is not authoritative for $i
    continue
  fi
  #
  # We know the server is authoritative; extract the serial number.
  #
  NAME=`cat /tmp/nso.$$ | grep "in-addr.arpa" | sed -e "s/.*= //"`
  if test "$NAME" = ""
  then
    #
    # We get here if NAME is null.  In this case, there should
    # be an error message from nslookup; so cat the "standard
    # error" file.
    #
    cat /tmp/nse.$$ > /dev/null
  else
    #
    # Report the server's domain name and its serial number.
    #
    echo $i has name $NAME
  fi
  ADDRESS=`cat /tmp/nso.$$ | ggrep -A1 $i | grep "^Address" | sed -e "s/.*: //"`
  if test "$ADDRESS" = ""
  then
    #
    # We get here if ADDRESS is null.  In this case, there should
    # be an error message from nslookup; so cat the "standard
    # error" file.
    #
    cat /tmp/nse.$$ > /dev/null
  else
    #
    # Report the server's domain name and its serial number.
    #
    echo $i has address $ADDRESS
  fi
done  # end of the "for" loop
#
# Delete the temporary files.
#
rm -f /tmp/nso.$$ /tmp/nse.$$ /tmp/testlookups.$$