You probably you forgot to turn on the '
tcp_service_check' option. If it's turned off (which it is by default) then ping will report success if it gets an explicit "connection denied" from the server (since that means the server is up -- otherwise it couldn't have denied the connection)
However, you don't want to check if the server itself is up but if a specific service is up, so a refused connection is a failure to you. If you turn on 'tcp_service_check', Net::Ping will only report success if it could actually establish a connection, and report failture if the connection was denied.
Example:
use strict;
use warnings;
use Net::Ping;
my $p = Net::Ping->new('tcp');
$p->tcp_service_check(1);
my $host = "192.168.100.12";
my $port = 80;
$p->{'port_num'} = $port;
print "The service on $host port $port is ",
($p->ping($host) ? "up" : "down"), ".\n";
•Update: Note that the tcp_service_check option isn't available in the Net::Ping that is included with perl 5.8.0, however it is available in the latest version.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.