Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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]
[Discipulus]: just in Eataly: brain surgery while playing clarinet..
[erix]: installing perfect pitch?
[karlgoethebier]: ...good Hot tuna. Note the stacks & racks in the background
[karlgoethebier]: ..the last hippies. They still perform. At least the survivors...
[Discipulus]: not survived

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-11-17 20:18 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.