Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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', ""); 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 |

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://356880]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-05-28 04:03 GMT
Find Nodes?
    Voting Booth?