Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
rb:dnsfowardrev [29/04/2015 13:56]
andrew
rb:dnsfowardrev [11/06/2015 17:36] (current)
andrew
Line 4: Line 4:
 <code bash> <code bash>
 $ cat forward-reverse-dns-check.sh ​ $ cat forward-reverse-dns-check.sh ​
 +
  
 #!/bin/bash #!/bin/bash
 # #
 # test DNS forward- and reverse-mapping # test DNS forward- and reverse-mapping
-#+Written Andrew Stringer July 2010 onwards... may even work now.
  
 # edit this variable to reflect local class C subnet(s) # edit this variable to reflect local class C subnet(s)
-NETS="192.168.1 192.168.5"+NETS="10.100.220" 
 + 
 +# Test address to name to address validity 
 +echo "Test ipaddress to host name lookup and then check hostname lookup to ipaddress."​ 
 +echo 
 + 
 +echo -e "\tIP address (PTR) -> hostname (A) -> IP address"​ 
 +echo '​-------------------------------------'​ 
 +for NET in $NETS; do 
 +  for n in $(seq 254); do 
 +    ADDRESS=${NET}.${n} 
 +    HOST=$(dig -x $ADDRESS +short) 
 +    if test -n "​$HOST";​ then 
 +      echo ${HOST} >> named-hosts 
 + 
 +      ADDR=$(dig $HOST +short) 
 +      if test "​$ADDRESS"​ = "​$ADDR";​ then 
 +        echo -e "​ok\t$ADDRESS -> $HOST -> $ADDR"​ 
 +      elif test -n "​$ADDR";​ then 
 +        echo -e "​fail\t$ADDRESS -> $HOST -> $ADDR"​ 
 +      else 
 +        echo -e "​fail\t$ADDRESS -> $HOST -> [unassigned]" 
 +      fi 
 +    fi 
 +  done 
 +done 
 + 
 +#get rid of blank lines with strings 
 + 
 +strings named-hosts > named-hosts1
  
 # Test name to address to name validity # Test name to address to name validity
 +echo "Test hostname to ipaddress lookup and then lookup up name from ipaddress."​
 echo echo
-echo -e "\tname -> address -> name"+echo -e "\thostname (A) -> ip address ​(PTR) -> hostname"
 echo '​----------------------------------'​ echo '​----------------------------------'​
 while read H; do while read H; do
Line 31: Line 62:
     echo -e "​fail\t$H -> [unassigned]"​     echo -e "​fail\t$H -> [unassigned]"​
   fi   fi
-done < named-hosts+done < named-hosts1 
  
-# Test address to name to address validity 
-echo 
-echo -e "​\taddress -> name -> address"​ 
-echo '​-------------------------------------'​ 
-for NET in $NETS; do 
-  for n in $(seq 1 254); do 
-    A=${NET}.${n} 
-    HOST=$(dig -x $A +short) 
-    if test -n "​$HOST";​ then 
-      ADDR=$(dig $HOST +short) 
-      if test "​$A"​ = "​$ADDR";​ then 
-        echo -e "​ok\t$A -> $HOST -> $ADDR" 
-      elif test -n "​$ADDR";​ then 
-        echo -e "​fail\t$A -> $HOST -> $ADDR" 
-      else 
-        echo -e "​fail\t$A -> $HOST -> [unassigned]"​ 
-      fi 
-    fi 
-  done 
-done 
  
 </​code>​ </​code>​

rb/dnsfowardrev.txt · Last modified: 11/06/2015 17:36 by andrew