Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Monitor webserver status on all machines in a subnet

by Chady (Priest)
on May 27, 2004 at 13:00 UTC ( [id://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/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found