Adig

From James Dooley's Wiki
Revision as of 15:46, 22 December 2011 by Smsldoo (talk | contribs) (Script)
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://svn.jamesdooley.us/svn/JDooley/adig/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 "\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 getnameservers { #$domain digresult=`dig +noall +authority $1 | awk '{print $5}'` cleaned=`echo "$digresult" | grep -v "<<>>" | grep -ve "^;;" | sed "/^$/d" | sort` echo "$cleaned" }

diglw=`getdig $1 "ns.liquidweb.com"` diggoogle=`getdig $1 "8.8.8.8"` dignorm=`getdig $1`

digns=`getnameservers $1`

printresults "Default dig results" "$dignorm" printresults "Liquid Web dig results" "$diglw" printresults "Google dig results" "$diggoogle"

for i in $(echo "$digns") do

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

done

IFS=$OIFS