#!/usr/bin/perl
print "Content-type: text/html \n\n";
use Time::Local;
use Time::localtime;
#########################################
# There are modules: #
# sub ip_to_num #
# sub ip_to_num #
# sub tm_to_td #
# sub dt_to_tm #
#########################################
#########################################################################
sub ip_to_num #
{
#
######################################### #
# IP-address to a number conversion #
#
######################################### #
my @Lm; #
my ($s)=@_; #
@Lm=split/\./,$s; #
if($#Lm < 3) {return -1;} #
else { return ((((($Lm[0]<<8)+$Lm[1])<<8)+$Lm[2])<<8)+$Lm[3]; #
} #
} #########
#########################################################################
# A number to IP-address conversion #
#########################################################################
sub num_to_ip #########
{ #
my $n=@_[0]; #
my $ip=$n>>24; # the first number #
$ip=$ip.".".($n>>16)%256; # the second number #
$ip=$ip.".".($n>>8)%256; # the third number #
$ip=$ip.".".$n%256; #
return($ip); #
} #########
#########################################################################
# Time-mark to Date and Time conversion #
#########################################################################
sub tm_to_td #########
{ #
use Time::localtime; #
my @mon=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
my $tk=@_[0];
#
$tm=localtime($tk); #
$seconds=$tm->sec; #
$mins=$tm->min; #
$hour=$tm->hour; #
$year=$tm->year+1900; #
$month=$tm->mon; #
$month=$mon[$month]; #
$day=$tm->mday; #
$dt=$day."/".$month."/".$year.":".$hour.":".$mins.":".$seconds; #
return($dt); #
} #
#########################################################################
########################################################
# Date-Time conversion to TM (TM=time-mark) #
# additional output - mins from the day beginning #
########################################################
sub dt_to_tm #########
{ #
use Time::Local; #
my $i; #
my @mon=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
my $date_time=@_[0]; #
my @MMM=split(/\:/,$date_time); #
if($#MMM==3){ # date terms number control #
my $date=$MMM[0]; #
my @NNN=split(/\//,$date); #
if(!(defined$NNN[0])) {$NNN[0]=1;} #
my $mday=$NNN[0]; #
if(!(defined$NNN[1])) {$NNN[1]=1;} #
my $month=$NNN[1]; #
for($i=0;$i<12;$i++){if($month eq $mon[$i]){$month=$i;}} #
if(!(defined$NNN[2])) {$NNN[2]=2;} #
my $year=$NNN[2]; #
$year=$year-1900; #
if(!(defined$MMM[1])) {$MMM[1]=1;} #
my $hours=$MMM[1]; #
if(!(defined$MMM[2])) {$MMM[2]=1;} #
my $minutes=$MMM[2]; #
if(!(defined$MMM[3])) {$MMM[3]=1;} #
my $seconds=$MMM[3]; #
my $cur_TIME=timelocal($seconds,$minutes,$hours,$mday,$month,$year);
return ($cur_TIME); #
} #
} #########