home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / network / dnscheck < prev    next >
Text File  |  2011-05-22  |  2KB  |  56 lines

  1. #! /bin/sh
  2. #
  3. # dnscheck [@seed nameserver] <FQDN>
  4. #
  5. # follows CNAME chain until it gets an A record
  6. # unrolls A record name until it finds SOA (zone name)
  7. # then queries each authoritative nameserver for the A record
  8. # lists out all IP addresses returned per nameserver
  9. #
  10. # Mirrored from http://lanning.cc/pub/dnscheck.  Credit goes to
  11. # Robert Hajime Lanning.  Note that this version of the script
  12. # gives wrong results on unqualified second-level domains.
  13.  
  14.  
  15. # default FQDN to lookup
  16. LB_HOSTNAME="www.google.com"
  17.  
  18. # parse arguments
  19. while [ "${#}" -gt "0" ]; do
  20.    if [ "${1:0:1}" = "@" ]; then
  21.       SEED="${1}"
  22.    else
  23.       LB_HOSTNAME="${1}"
  24.    fi
  25.    shift
  26. done
  27.  
  28. # Follow CNAME chain
  29. for CNAME in `dig ${SEED} ${LB_HOSTNAME} A +short|grep '\.$'`; do
  30.    echo "CNAME: ${LB_HOSTNAME} -> ${CNAME}"
  31.    LB_HOSTNAME="${CNAME}"
  32. done
  33.  
  34. # unroll A record name, until SOA found
  35. LB_DOMAIN="${LB_HOSTNAME#*.}"
  36. while [ -n "${LB_DOMAIN}" ] && [ -z "`dig ${SEED} ${LB_DOMAIN} soa +short`" ]; do
  37.    LB_DOMAIN="${LB_DOMAIN#*.}"
  38. done
  39.  
  40. # report headers
  41. echo "Host: ${LB_HOSTNAME}"
  42. echo "Zone: ${LB_DOMAIN}"
  43. echo "NameServer            IP List..."
  44. echo "--------------------  ----------------"
  45.  
  46. # retrieve list of authoritative nameserver and iterate through them
  47. # querying A records from each one and listing them out
  48. dig ${SEED} ${LB_DOMAIN} ns +short | sort | uniq |\
  49. while read NAMESERVER; do
  50.    IPLIST="`dig \@${NAMESERVER} ${LB_HOSTNAME} A +short +norecurse | sed -e 's/^;; connection timed out.*$/TIMEOUT/' -e '/;.*$/d' | sort | xargs echo -n`"
  51.    NAMESERVER="${NAMESERVER}                      "
  52.    echo "${NAMESERVER:0:20}  ${IPLIST:-NXDOMAIN}"
  53. done
  54.  
  55.  
  56.