#!/usr/bin/perl
##############################################################################################
#                                                                                            #
# When Was That Site Last Updated?                                                           #
# Written By: Samuel Sparling                                                                #
#                                                                                            #
# The script is intended to be used as a Server Side Include, although it can be used as a   #
# stand-alone script. The idea behind this script is to see when a website was last updated. #
# The output is simply the date and time that the file being checked was last updated. This  #
# can be used on a site to show users when a particular site has been updated, so that if    #
# the site hasn't been updated, the user need not waste his/her time in visiting the site.   #
#                                                                                            #
# This script is released as open source freeware. You may modify this script in any way     #
# you choose, so long as I am given credit for the original script.                          #
#                                                                                            #
##############################################################################################
#
use Socket;

# The server on which the file we'll be checking is located.
$remote = "packetstorm.securify.com";

# The port that the HTTP server is running on.
$port = 80;

# The file that we'll be checking.
$checkfile = "whatsnew20.html";


	$submit = "HEAD $checkfile HTTP/1.0\r\n\r\n";
	if($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
	&error("No port specified.") unless $port;
	$iaddr = inet_aton($remote) || &error("Failed to find host: $remote");
	$paddr = sockaddr_in($port, $iaddr) || &error("Some fucking thing!");
	$proto = getprotobyname('tcp') || &error("Unable to get protocall!");

        socket(SOCK, PF_INET, SOCK_STREAM, $proto) || &error("Failed to open socket: $!");
	connect(SOCK, $paddr) || &error("Unable to connect: $!");
	send(SOCK,$submit,0);
	while(<SOCK>) {
		if($_ =~ /Last-Modified: /) { $changed = $_; close(SOCK); }
		}
	close(SOCK);

$changed =~ s/Last-Modified: //g;
print "Content-type: text/html\n\n";
print $changed;

exit;


sub error
{
	$error = shift(@_);
	print "Error - $error\n";
	exit;
}
