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/

In reply to Re: Monitor webserver status on all machines in a subnet by Chady
in thread Monitor webserver status on all machines in a subnet by chimni

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.