BBQ has asked for the wisdom of the Perl Monks concerning the following question:

I found this shell line over at insecure.org and decided it would be a nice exercise to do it entirely in perl. Its a little trick with netcat and grep to pull out the server header from an http request...

#!/usr/bin/perl # What The Server Is RUNning # get the server make (and maybe OS) by GETting # a simple query via http... if (!$ARGV[0]) { print "Usage: witsirun.pl [host] [port]\n"; } else { $ARGV[1] = 80 if ! $ARGV[1]; print "Getting "; print `echo 'GET / HTTP/1.0\n' | netcat $ARGV[0] $ARGV[1] | grep '^S +erver:'`; }
Would anyone care to take a stab at a best approach to doing this? Use sockets and a while on the file handle?

Cheers!

Replies are listed 'Best First'.
Re: What The Server Is RUNning
by httptech (Chaplain) on Apr 23, 2000 at 04:26 UTC
    perl -MLWP::Simple -e 'print @{[head("http://www.perlmonks.org/")]}[2] + . "\n"'
    Not sure why this works; according to LWP::Simple POD the server string is supposed to be array element 4.
      With a one-liner you have successfully taken the joy out of my little exercise. kudos! :o)