Adig

From James Dooley's Wiki
Revision as of 17:41, 17 February 2012 by Smsldoo (talk | contribs)
Jump to: navigation, search

Overview

Advanced dig script that queries default name server on your workstation, google, the liquidweb name server and name servers returned by dig (/registrar).

Good for finding differences being reported by different name servers.

Searching for main domain will return all record types (A,MX,TXT,NS,CNAME etc).

Searching for subdomain will generally only return CNAME and A records.

Color codes records for easier viewing.

This should not be installed on customer servers

Installation

[bash,n] wget http://scripts.ent.liquidweb.com/adig -O /usr/bin/adig && chmod +x /usr/bin/adig

Usage

[bash,n] adig site.com

Script

[bash,n]

  1. !/bin/bash

OIFS=$IFS;IFS=$'\n'

function printresults {

       #$1 Title
       #$2 Message
       echo -e "\t\e[01;32m=== $1 ===\e[0m"
       for r in $(echo "$2")
       do
               echo -e "`colorresult $r`"
       done

}

function colorresult {

       rtype=`echo "$1" | awk '{print $4}'`
       case $rtype in
               A)
                       echo "\e[0;32m`echo "$1"`\e[0m"
                       ;;
               MX)
                       echo "\e[0;31m`echo "$1"`\e[0m"
                       ;;
               TXT)
                       echo "\e[0;34m`echo "$1"`\e[0m"
                       ;;
               NS)
                       echo "\e[0;36m`echo "$1"`\e[0m"
                       ;;
               CNAME)
                       echo "\e[0;35m`echo "$1"`\e[0m"
                       ;;
               *)
                       echo "$1"
                       ;;
       esac

}

function getdig {

       #$1 domain
       #$2 against
       if [ -n "$2" ]
       then
               digresult=`dig $1 ANY +noall +answer @$2`
       else
               digresult=`dig $1 ANY +noall +answer`
       fi
       cleaned=`echo "$digresult" | grep -v "<<>>" | grep -ve "^;;" | sed "/^$/d" | sort -k 4`
       echo "$cleaned"

}

function getdigns { #$1 domain digresult=`dig +noall +authority $1 | awk '{print $5}'` cleaned=`echo "$digresult" | grep -v "<<>>" | grep -ve "^;;" | sed "/^$/d" | sort | sed "s/\.$//"` echo "${cleaned,,}" }

function printusage { echo "Return dig results from several different name servers" echo "Usage: adig DOMAIN" }

if [ ! -n "$1" ] then printusage exit fi

printresults "Digging against resolv.conf" "`getdig $1`" printresults "Digging against liquidweb.com" "`getdig $1 'ns.liquidweb.com'`" printresults "Digging against google.com" "`getdig $1 '8.8.8.8'`"

for i in $(getdigns $1) do

       printresults "Digging against $i" "`getdig $1 $i`"

done

IFS=$OIFS