Difference between revisions of "Adig"

From James Dooley's Wiki
Jump to: navigation, search
(Created page with "==Overview== Advanced dig script that queries default name server on your workstation, google and name servers returned by dig. Good for finding differences being reported by di...")
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Scripts]]
 
==Overview==
 
==Overview==
Advanced dig script that queries default name server on your workstation, google and name servers returned by dig.
+
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.
 
Good for finding differences being reported by different name servers.
Line 9: Line 10:
  
 
Color codes records for easier viewing.
 
Color codes records for easier viewing.
 +
 +
'''This should not be installed on customer servers'''
  
 
==Installation==
 
==Installation==
  
<code>[bash,n]
+
<source lang='bash'>
wget http://svn.jamesdooley.us/svn/JDooley/adig/adig -O /usr/bin/adig && chmod +x /usr/bin/adig
+
wget http://scripts.ent.liquidweb.com/adig -O /usr/bin/adig && chmod +x /usr/bin/adig
</code>
+
</source>
  
 
==Usage==
 
==Usage==
  
<code>[bash,n]
+
<source lang='bash'>
 
adig site.com
 
adig site.com
</code>
+
</source>
  
 
==Script==
 
==Script==
  
<code>[bash,n]
+
<source lang='bash'>
 
#!/bin/bash
 
#!/bin/bash
 
OIFS=$IFS;IFS=$'\n'
 
OIFS=$IFS;IFS=$'\n'
Line 31: Line 34:
 
         #$1 Title
 
         #$1 Title
 
         #$2 Message
 
         #$2 Message
         echo -e "\e[01;32m=== $1 ===\e[0m"
+
         echo -e "\t\e[01;32m=== $1 ===\e[0m"
 
         for r in $(echo "$2")
 
         for r in $(echo "$2")
 
         do
 
         do
Line 75: Line 78:
 
}
 
}
  
diglw=`getdig $1 "ns.liquidweb.com"`
+
function getdigns {
diggoogle=`getdig $1 "8.8.8.8"`
+
#$1 domain
dignorm=`getdig $1`
+
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"
 +
}
  
tld=`echo $1 | rev | cut -d'.' -f1,2 | rev`
+
if [ ! -n "$1" ]
digns=`dig $tld NS +short`
+
then
 +
printusage
 +
exit
 +
fi
  
printresults "Default dig results" "$dignorm"
+
printresults "Digging against resolv.conf" "`getdig $1`"
printresults "Liquid Web dig results" "$diglw"
+
printresults "Digging against liquidweb.com" "`getdig $1 'ns.liquidweb.com'`"
printresults "Google dig results" "$diggoogle"
+
printresults "Digging against google.com" "`getdig $1 '8.8.8.8'`"
  
for i in $(echo "$digns")
+
for i in $(getdigns $1)
 
do
 
do
        digresult=`getdig $1 $i`
+
         printresults "Digging against $i" "`getdig $1 $i`"
         printresults "Digging against $i" "$digresult"
 
 
done
 
done
  
 
IFS=$OIFS
 
IFS=$OIFS
</code>
+
</source>

Latest revision as of 14:30, 25 March 2014

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

wget http://scripts.ent.liquidweb.com/adig -O /usr/bin/adig && chmod +x /usr/bin/adig

Usage

adig site.com

Script

#!/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