> Sir Douglas Cook wrote:
>
> > Question:
> > I am wondering how to test if my PWS is UP?
> > If (http://65.93.27.6/MyHomepageOnSympaticoServer/) {
Here's a way:
use strict;
use Net::Telnet;

my $timeout = 5;
my $_ERR = '';
my $header = {
    www    => { port => 80,   print => "HEAD / HTTP/1.0\n\n", waitfor =>
'/200/' }
};

my $host = '65.93.27.6'; # Takes either IP Address or FQDN
my $service = 'www';

# Check the www service on the remote host
if (&check_service($host,$service)) {
    print "$host $service is operational.\n\n";
} else {
    print "$host $service in not operational\n";
}

sub check_service {
    my ($host,$service) = @_;

    # Setup
    my $port    = $header->{$service}->{port};
    my $sock    = new Net::Telnet (Telnetmode => 0);
    my $waitfor = $header->{$service}->{waitfor};

    # Create a connection to the remote host
    eval {
          $sock->open(Host     => $host,
                        Port     => $port,
                      Timeout  => $timeout
         );
    };

    # Catch any errors
    if ($@) {
        $_ERR = "Cannot establish connection to host";
        return 0;
    }

    # Send HEAD to host
    $sock->print($header->{$service}->{print}) if
$header->{$service}->{print};

    # Wait for the "waitfor" match
    if (!($sock->waitfor($waitfor))) {
        $_ERR = "Timed out waiting for $waitfor";
        return 0;
    }

    # Test went OK
    return 1;
}

__END__
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.333 / Virus Database: 187 - Release Date: 08/03/2002


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to