Listing 9. getservertype1.pl

#!/usr/bin/perl -w
# getservertype1.pl - non-forking, non-threading
# solution to get the web server used on several
# web sites
use strict;
use IO::Socket;
my @hosts = qw(
    www.ssc.com
    www.linuxjournal.com
    www.perl.com
    www.perl.org
    www.nytimes.com
    www.onsight.com
    www.avue.com
);
sub doit {
    my $server = shift;
    print "processing $server...\n";
    my $sock = new IO::Socket::INET(
                    PeerAddr => $server,
                    PeerPort => 80,
                    Proto    => 'tcp');
    $sock or die "no socket for $_: $!";
    print $sock "GET / HTTP/1.0\n\n";
    while (<$sock>) {
   if (/^Server:\s*(.*)/) {
       print "    $server: $1\n";
       last;
   }
    }
}
for (@hosts) {
    doit $_;
}