[Fsf-friends] [LIG]Query on scripts to study servers ...
Raju Mathur
raju@linux-delhi.org
Tue, 27 Aug 2002 07:19:19 +0530
>>>>> "Fred" == Frederick Noronha <fred@bytesforall.org> writes:
Fred> Could someone help me with this task? I need some scripts
Fred> that would help me to search for the type of servers a
Fred> particular host is running. (One could use netcraft.com to
Fred> find that out, but it would be rather time-consuming.) On
Fred> the other hand, scripts which could automate this task would
Fred> help me to collect the info and dump those in a file. How
Fred> difficult would this task be? Do let me know... FN PS: If
Fred> someone could give me cost estimate for writing the script,
Fred> I'd be grateful...
You owe me a soda when I'm next in Goa :)
-- Raju
<snip>
#!/usr/bin/perl -w
#
# Script to get HOST header from HTTP servers
#
# Raj Mathur, Tue Aug 27 07:10:14 IST 2002
#
use strict ;
use LWP::UserAgent ;
# Check command-line
if ( $#ARGV == -1 )
{
print STDERR "Nothing to do! Exiting.\n" ;
exit ( 1 ) ;
}
# Create a UserAgent. This needs to be done only once in the program.
my
$agent = new LWP::UserAgent ;
$agent -> agent ( "OldMonks host header checket v1.0" ) ;
# Process each argument on the command line.
foreach my $url ( @ARGV )
{
# Create the request.
my
$request = new HTTP::Request ( HEAD => $url ) ;
# Get the user agent to handle the request and grab the response.
my
$response = $agent -> request ( $request ) ;
# Was the request successful?
if ( !$response -> is_success () )
{
print "*** $url: Error " , $response -> code () , "\n" ;
next ;
}
# Print out identification followed by headers.
my
$server = $response -> headers () -> {server} ;
print "$url: $server\n" ;
}
# Done
exit 0 ;
</snip>
--
Raju Mathur raju@kandalaya.org http://kandalaya.org/
It is the mind that moves