scripts/domain-check
changeset 21 14a903cf9505
parent 20 fe1c8b4725f7
child 22 4bccc75a8a1c
equal deleted inserted replaced
20:fe1c8b4725f7 21:14a903cf9505
     3 # Source: http://www.cyberciti.biz/files/scripts/domain-check-2.txt
     3 # Source: http://www.cyberciti.biz/files/scripts/domain-check-2.txt
     4 # Program: Domain Expiration Check <domain-check>
     4 # Program: Domain Expiration Check <domain-check>
     5 #
     5 #
     6 # Author: Matty < matty91 at gmail dot com >
     6 # Author: Matty < matty91 at gmail dot com >
     7 # 
     7 # 
     8 # Current Version: 1.9
     8 # Current Version: 1.95
     9 #
     9 #
    10 # Revision History:
    10 # Revision History:
       
    11 #  Version 1.95
       
    12 #    Added support for .ie and .us domain names
       
    13 #    Cleaned up some areas where awk and cut were being called
       
    14 #    directly rather than from the variables they were asigned to. -- Chris Jones <chris@sysadminchris.com>
    11 #  Version 1.9
    15 #  Version 1.9
    12 #    Bug fix and enhancement for .uk and .co.uk -- Vivek Gite <vivek@nixcraft.com>
    16 #    Bug fix and enhancement for .uk and .co.uk -- Vivek Gite <vivek@nixcraft.com>
    13 #
    17 #
    14 #  Version 1.8
    18 #  Version 1.8
    15 #    Bug fix added $MAIL -- Vivek Gite <vivek@nixcraft.com>
    19 #    Bug fix added $MAIL -- Vivek Gite <vivek@nixcraft.com>
   222     local REGISTRAR=""
   226     local REGISTRAR=""
   223     # Avoid WHOIS LIMIT EXCEEDED - slowdown our whois client by adding 3 sec 
   227     # Avoid WHOIS LIMIT EXCEEDED - slowdown our whois client by adding 3 sec 
   224     sleep 3
   228     sleep 3
   225     # Save the domain since set will trip up the ordering
   229     # Save the domain since set will trip up the ordering
   226     DOMAIN=${1}
   230     DOMAIN=${1}
   227     TLDTYPE="`echo ${DOMAIN} | cut -d '.' -f3 | tr '[A-Z]' '[a-z]'`" 
   231     TLDTYPE="`echo ${DOMAIN} | ${CUT} -d '.' -f3 | tr '[A-Z]' '[a-z]'`" 
   228     if [ "${TLDTYPE}"  == "" ];
   232     if [ "${TLDTYPE}"  == "" ];
   229     then
   233     then
   230 	    TLDTYPE="`echo ${DOMAIN} | cut -d '.' -f2 | tr '[A-Z]' '[a-z]'`" 
   234 	    TLDTYPE="`echo ${DOMAIN} | ${CUT} -d '.' -f2 | tr '[A-Z]' '[a-z]'`" 
   231     fi
   235     fi
   232 
   236 
   233     # Invoke whois to find the domain registrar and expiration date
   237     # Invoke whois to find the domain registrar and expiration date
   234     #${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
   238     #${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
   235     # Let whois select server 
   239     # Let whois select server 
   244         ${WHOIS} -h "whois.nic.uk" "${1}" > ${WHOIS_TMP}
   248         ${WHOIS} -h "whois.nic.uk" "${1}" > ${WHOIS_TMP}
   245 
   249 
   246     elif [ "${TLDTYPE}"  == "biz" ];
   250     elif [ "${TLDTYPE}"  == "biz" ];
   247     then
   251     then
   248         ${WHOIS} -h "whois.neulevel.biz" "${1}" > ${WHOIS_TMP}
   252         ${WHOIS} -h "whois.neulevel.biz" "${1}" > ${WHOIS_TMP}
       
   253     elif [ "${TLDTYPE}"  == "ie" ]; # Ireland
       
   254     then
       
   255         ${WHOIS} -h "whois.domainregistry.ie" "${1}" > ${WHOIS_TMP}
   249     elif [ "${TLDTYPE}"  == "info" ];
   256     elif [ "${TLDTYPE}"  == "info" ];
   250     then
   257     then
   251         ${WHOIS} -h "whois.afilias.info" "${1}" > ${WHOIS_TMP}
   258         ${WHOIS} -h "whois.afilias.info" "${1}" > ${WHOIS_TMP}
   252     elif [ "${TLDTYPE}"  == "jp" ]; # Japan
   259     elif [ "${TLDTYPE}"  == "jp" ]; # Japan
   253     then
   260     then
   254         ${WHOIS} -h "whois.jprs.jp" "${1}" > ${WHOIS_TMP}
   261         ${WHOIS} -h "whois.jprs.jp" "${1}" > ${WHOIS_TMP}
       
   262     elif [ "${TLDTYPE}"  == "us" ];
       
   263     then
       
   264         ${WHOIS} -h "whois.nic.us" "${1}" > ${WHOIS_TMP}
   255 
   265 
   256     elif [ "${TLDTYPE}"  == "com" -o "${TLDTYPE}"  == "net" -o "${TLDTYPE}"  == "edu" ];
   266     elif [ "${TLDTYPE}"  == "com" -o "${TLDTYPE}"  == "net" -o "${TLDTYPE}"  == "edu" ];
   257     then
   267     then
   258 	${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
   268 	${WHOIS} -h ${WHOIS_SERVER} "=${1}" > ${WHOIS_TMP}
   259     else
   269     else
   270     then
   280     then
   271         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrant/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
   281         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/Registrant/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
   272     elif [ "${TLDTYPE}" == "cz" ];
   282     elif [ "${TLDTYPE}" == "cz" ];
   273     then
   283     then
   274         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/registrar:/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
   284         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/registrar:/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
       
   285     elif [ "${TLDTYPE}" == "ie" ]; # for .ie domain
       
   286     then
       
   287         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} '/source/ && $2 != ""  { REGISTRAR=substr($2,1,17) } END { print REGISTRAR }'`
       
   288     elif [ "${TLDTYPE}" == "us" ];
       
   289     then
       
   290         REGISTRAR=`cat ${WHOIS_TMP} | ${AWK} -F: '/Last Updated by Registrar:/ && $2 != ""  { REGISTRAR=substr($2,20,17) } END { print REGISTRAR }'`
   275     fi
   291     fi
   276 
   292 
   277     # If the Registrar is NULL, then we didn't get any data
   293     # If the Registrar is NULL, then we didn't get any data
   278     if [ "${REGISTRAR}" = "" ]
   294     if [ "${REGISTRAR}" = "" ]
   279     then
   295     then
   284     # The whois Expiration data should resemble the following: "Expiration Date: 09-may-2008"
   300     # The whois Expiration data should resemble the following: "Expiration Date: 09-may-2008"
   285 
   301 
   286     # for .in, .info, .org domains
   302     # for .in, .info, .org domains
   287     if [ "${TLDTYPE}" == "in" -o "${TLDTYPE}" == "info" -o "${TLDTYPE}" == "org" ];
   303     if [ "${TLDTYPE}" == "in" -o "${TLDTYPE}" == "info" -o "${TLDTYPE}" == "org" ];
   288     then
   304     then
   289 	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration Date:/ { print $2 }' | cut -d':' -f2`
   305 	    DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Expiration Date:/ { print $2 }' | ${CUT} -d':' -f2`
   290     elif [ "${TLDTYPE}" == "biz" ]; # for .biz domain
   306     elif [ "${TLDTYPE}" == "biz" ]; # for .biz domain
   291     then
   307     then
   292             DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`
   308             DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`
       
   309     elif [ "${TLDTYPE}" == "ie" ]; # for .ie domain
       
   310     then
       
   311             tdomdate=`cat ${WHOIS_TMP} | ${AWK} '/renewal/ { print $2 }'`
       
   312             tyear=`echo ${tdomdate} | ${CUT} -d'-' -f3`
       
   313             tmon=`echo ${tdomdate} | ${CUT} -d'-' -f2`
       
   314 	       case ${tmon} in
       
   315 	             "January") tmonth=jan ;;
       
   316 	             "February") tmonth=feb ;;
       
   317 	             "March") tmonth=mar ;;
       
   318 	             "April") tmonth=apr ;;
       
   319 	             "May") tmonth=may ;;
       
   320 	             "June") tmonth=jun ;;
       
   321 	             "July") tmonth=jul ;;
       
   322 	             "August") tmonth=aug ;;
       
   323 	             "September") tmonth=sep ;;
       
   324 	             "October")tmonth=oct ;;
       
   325 	             "November") tmonth=nov ;;
       
   326 	             "December") tmonth=dec ;;
       
   327                	      *) tmonth=0 ;;
       
   328 		esac
       
   329             tday=`echo ${tdomdate} | ${CUT} -d'-' -f1`
       
   330 	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
   293     elif [ "${TLDTYPE}" == "uk" ]; # for .uk domain
   331     elif [ "${TLDTYPE}" == "uk" ]; # for .uk domain
   294     then
   332     then
   295             DOMAINDATE=`cat ${WHOIS_TMP} | awk '/Renewal date:/ || /Expiry date:/ { print $3 }'`
   333             DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Renewal date:/ || /Expiry date:/ { print $3 }'`
       
   334     elif [ "${TLDTYPE}" == "us" ]; # for .us domain
       
   335     then
       
   336             DOMAINDATE=`cat ${WHOIS_TMP} | ${AWK} '/Domain Expiration Date:/ { print $6"-"$5"-"$9 }'`
   296     elif [ "${TLDTYPE}" == "jp" ]; # for .jp 2010/04/30
   337     elif [ "${TLDTYPE}" == "jp" ]; # for .jp 2010/04/30
   297     then
   338     then
   298 	    tdomdate=`cat ${WHOIS_TMP} | awk '/Expires on/ { print $3 }'`
   339 	    tdomdate=`cat ${WHOIS_TMP} | ${AWK} '/Expires on/ { print $3 }'`
   299             tyear=`echo ${tdomdate} | cut -d'/' -f1`
   340             tyear=`echo ${tdomdate} | ${CUT} -d'/' -f1`
   300             tmon=`echo ${tdomdate} | cut -d'/' -f2`
   341             tmon=`echo ${tdomdate} | ${CUT} -d'/' -f2`
   301 	       case ${tmon} in
   342 	       case ${tmon} in
   302 	             1|01) tmonth=jan ;;
   343 	             1|01) tmonth=jan ;;
   303 	             2|02) tmonth=feb ;;
   344 	             2|02) tmonth=feb ;;
   304 	             3|03) tmonth=mar ;;
   345 	             3|03) tmonth=mar ;;
   305 	             4|04) tmonth=apr ;;
   346 	             4|04) tmonth=apr ;;
   311 	             10)tmonth=oct ;;
   352 	             10)tmonth=oct ;;
   312 	             11) tmonth=nov ;;
   353 	             11) tmonth=nov ;;
   313 	             12) tmonth=dec ;;
   354 	             12) tmonth=dec ;;
   314                	      *) tmonth=0 ;;
   355                	      *) tmonth=0 ;;
   315 		esac
   356 		esac
   316             tday=`echo ${tdomdate} | cut -d'/' -f3`
   357             tday=`echo ${tdomdate} | ${CUT} -d'/' -f3`
   317 	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
   358 	    DOMAINDATE=`echo $tday-$tmonth-$tyear`
   318     elif [ "${TLDTYPE}" == "cz" ]; # for .cz 08.02.2013 dd.mm.yyyy
   359     elif [ "${TLDTYPE}" == "cz" ]; # for .cz 08.02.2013 dd.mm.yyyy
   319     then
   360     then
   320 	    tdomdate=`cat ${WHOIS_TMP} | awk '/expire:/ { print $2 }'`
   361 	    tdomdate=`cat ${WHOIS_TMP} | awk '/expire:/ { print $2 }'`
   321         tyear=`echo ${tdomdate} | cut -d'.' -f3`
   362         tyear=`echo ${tdomdate} | cut -d'.' -f3`