Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Monitor webserver status on all machines in a subnet

by Chady (Priest)
on May 27, 2004 at 13:00 UTC ( #356880=note: print w/ replies, xml ) Need Help??


in reply to Monitor webserver status on all machines in a subnet

Just as Abigail has pointed out, you have to issue a request to the webserver to see if it is really running, and not just something listening on the port. ex:

require LWP::UserAgent; my $ua = LWP::UserAgent->new(timeout => 10, agent => 'subnet monitor' ); my $request = HTTP::Request->new('HEAD', "http://perlmonks.org/"); my $contents = $ua->request($request); print $contents->{_rc} == 200 ? "Webserver Up" : "Webserver Down";

Update: As for if the server is running on a different port, you might want to experiment with Net::Telnet

Possibly something like this:

sub check { my ($host, $port) = @_; my $telnet = new Net::Telnet (errmode=> 'return'); my $return = $telnet->open(Host => $host, Port=> $port); unless ($return) { print "Nothing running on port $port.\n"; return; } my $res = $telnet->getline; $telnet->print("HEAD / HTTP/1.0\n\n"); $res = $telnet->getline; if ($res =~ /200 OK/) { print "Webserver Up\n"; } else { print "Webserver Down\n"; } $telnet->close(); }

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/


Comment on Re: Monitor webserver status on all machines in a subnet
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://356880]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-09-19 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls