#!/usr/bin/perl -w

##########################################################################################################################
# 							expirydate.pl						         # 
#					 Gaurang K. Pandya [gaubrig at yahoo.com]  				         # 
##########################################################################################################################
# 															 #
# This script fetches expiry date of a given domain (only of specific TLDs) if its name server is one of given server 	 #
# and convets that date into mysql date format. At present it can convert date only for selected tlds which are 	 #
#						com,org,net,in,edu,info,biz,ac,coop		 			 #
# 															 #
########################################################################################################################## 
# 							::NOTE:: 							 #
# The script can optionally be reconfigured in such a way that it will not check the NS for a domain by commenting some  #
# parts of it as given in script.											 #
#															 #
##########################################################################################################################
# 						     ::DISCLAIMER:: 							 #
#            This script has been provided "AS IS" and for free. Use it at YOUR own risk. Works well for me, 		 # 
#      your's *MAY* be different!!!. You are expected to test it before using it in live production server. 		 # 
##########################################################################################################################
# Latest copy of this script can be found at 										 #
# 															 #
# http://www.geocities.com/gaurangpandya/scripts/expirydate.pl.htm 							 #
# 															 #
# Let me know your commants/suggesions about the script and if you  make any changes to it. 				 #
# 															 #
# You may not like the way I am doing whois query, might want to do it using nagive perl functions.		 	 #
# 															 #
##########################################################################################################################

use Switch;

sub gettld
{
        my $text=$_[0];
        $off=rindex($text,".");
        $off++;
        return substr($text,$off);
}

sub trim {
    my $string = shift;
    for ($string) {
        s/^\s+//;
        s/\s+$//;
    }
    return $string;
}

sub strdatlen
{
        my $string=$_[0];
        my ($colon,$dot,$strdatelen)=(0,0,0);
        $colon=index($string,":");
        $dot=index($string,".");
#       $strdatelen=$dot-$colon+1;   Converted exactly from basic might not work.
        $strdatelen=$dot-$colon-1;
        return $strdatelen
}

sub convmon
{
        my $str=lc $_[0];
        my $mm="00";
        switch ($str)
        {
                case ["jan","january"]   { $mm="01"; }
                case ["feb","february"]  { $mm="02"; }
                case ["mar","march"]     { $mm="03"; }
                case ["apr","april"]     { $mm="04"; }
                case ["may"]             { $mm="05"; }
                case ["jun","june"]      { $mm="06"; }
                case ["jul","july"]      { $mm="07"; }
                case ["aug","august"]    { $mm="08"; }
                case ["sep","september"] { $mm="09"; }
                case ["oct","october"]   { $mm="10"; }
                case ["nov","november"]  { $mm="11"; }
                case ["dec","december"]  { $mm="12"; }
        }
        return $mm;
}

sub convdate
{
        my $dat=lc $_[0];
        my $tldom=lc $_[1];
        my ($mm,$dd,$yyyy)=("","","");
        my ($fs,$ss)=(0,0);
        my $datlen=length $dat;

        switch ($tldom)
        {
                case ["org","net","com","info","in","edu"]
                {
                        $mm=convmon(substr($dat,3,3));
                        $dd=substr($dat,0,2);
                        $yyyy=substr($dat,$datlen-4,4);
                }
                case "biz"
                {
                        $mm=convmon(substr($dat,4,3));
                        $dd=substr($dat,8,2);
                        $yyyy=substr($dat,$datlen-4,4);
                }
                case "coop"
                {
                        $dd=substr($dat,0,2);
                        $mm=convmon(substr($dat,3,3));
                        $yyyy=substr($dat,$datlen-4,4);
                }
                case "ac"
                {
                        $yyyy=substr($dat,$datlen-4,4);
                        $fs=index($dat," ");
                        $ss=rindex($dat," ");
                        $mm=convmon(substr($dat,0,$fs-1));
                        $dd=substr($dat,$fs+1,($ss-$fs));
                        if ( (length $dat) == 1 ) { $dd="0".$dd }
                }
        }
        return $yyyy."-".$mm."-".$dd;
}

$domname=;
chomp($domname);
my $tld=gettld($domname);
my ($withns,$i,$j,$lin,$lexp)=(0,0,0);
my ($da,$dat,$ltlin)=("","","");

########################### give FQDN of Name servers below to be checked in whois query for ########################
my @chkns=qw( ns1.domain.dom ns2.domain.dom ns3.domain.com );
my $domlen=@chkns;

switch ($tld){
        case "com"
        {
                $srvr="whois.internic.net ";
                $exprstr = lc "Expiration Date: ";
                $dl=11;
        }
        case "org"
        {
                $srvr="whois.pir.org ";
                $exprstr = lc "Expiration Date:";
                $dl=11;
        }
        case "net"
        {
                $srvr="whois.internic.net ";
                $exprstr = lc "Expiration Date: ";
                $dl=11;
        }
        case "in"
        {
                $srvr="whois.inregistry.in ";
                $exprstr = lc "Expiration Date:";
                $dl=11;
        }
        case "edu"
        {
                $srvr="whois.educause.edu ";
                $exprstr= lc "Domain expires:"." "x13;
		$dl=11;
        }
        case "info"
        {
                $srvr="whois.afilias.net ";
                $exprstr = lc "Expiration Date:";
                $dl=11;
        }
        case "biz"
        {
                $srvr="whois.biz ";
                $exprstr = lc "Domain Expiration Date:"." "x22;
                $dl=34;
        }
        case "ac"
        {
                $srvr="whois.nic.ac ";
                $exprst = lc "Expires"." "x8;
                $exprstr="$exprst".": ";
        }
        case "coop"
        {
                $srvr="whois.nic.coop ";
                $exprstr = lc "Expiry Date:"." "x13;
                $dl=11;
        }
        else
        {
                $srvr="junkserver.whois ";
                $exprstr = lc "Junk Server Strig";
                $dl=11;
        }
}

if ($srvr ne "junkserver.whois " )
{
        $cmd="whois -n -h "."$srvr"."$domname";
        $op=`$cmd`;
        @all=split(/\n/,$op);
        $arrlen=@all;
########################################### Check if domain is with given NS #####################################
#	Comment below given for loop and set $withns variable to 1 explicitly to skip NS check			 #
##################################################################################################################
        for($i=0;$i<$arrlen;$i++)
        {
                $myline=lc $all[$i];
                for($j=0;$j<$domlen;$j++)
                {
                        if ( index($myline,$chkns[$j]) != -1 )
                        {
                          $withns=1;
                          goto OUT;
                        }
                }
        }
###################### to skip NS Checking Comment till this & Uncomment next line ##############################
##$withns=1;

OUT:            if($withns == 1)
                {
                          for ($i=0;$i<$arrlen;$i++)
                          {
                                $myline=lc $all[$i];
                                if ( index($myline,$exprstr) != -1 )
                                {
                                        $ltin=trim($myline);
                                        $lin=length $ltin;
                                        $lexp=length $exprstr;
                                        if ( $tld eq "ac" ) { $dl=strdatlen($myline); }
                                        $dat=substr($ltin,$lexp,$dl);
                                        if ( $lin > $lexp ) { $da=convdate($dat,$tld); }
                                        print $da;
                                }
                        }
                      
                }
                else
                {
                        print "Not-With-NS";
                }
}
else
{
        print "Dont-know-how-to";
}

Hosted by www.Geocities.ws

1