in reply to Solution to broken Net::Ping

I am guessing its the module

guessing virtually guarantees it is not the module

Ah yes, and you are the first person to have noticed this bug since 1994. Sure.

The Net::Ping description says

You may choose one of six different protocols to use for the ping. The "tcp" protocol is the default. Note that a live remote host may still fail to be pingable by one or more of these protocols. For example, www.microsoft.com is generally alive but not "icmp" pingable.
$ perl -MNet::Ping -le " print !! Net::Ping->new->ping( shift ) " loca +lhost 1 $ perl -MNet::Ping -le " print !! Net::Ping->new->ping( shift ) " goog +le.com $ perl -MNet::Ping -le " print !! Net::Ping->new( qw/syn/ )->ping( shi +ft ) " google.com 1

Replies are listed 'Best First'.
Re^2: Solution to broken Net::Ping
by solignis (Initiate) on Dec 16, 2011 at 09:16 UTC

    I am aware that certain hosts are not always pingable.

    After a little RTFM it works now (what a surprise).

    Based on the above it looks like I need to create 2 ping tests (1 for icmp, 1 for tcp port test). Would it be cleaner to create the first object then undef it and recreate the object with the new options? or just create 2 different objects and destroy them after their very short lifespan?

    Thank you for your help

      Since I don't see an official way to change protocol choice after the fact, I recommend limiting scope with functions, however many you need , maybe

      sub MahPing { my ( $host ) = @_; for my $proto ( qw/ tcp icmp syn / ){ return !!1 if Net::Ping->new( $proto, 5 ) ->ping( $host ); } return !!0; }

      If you're concerned about performance, Benchmark it, not against some production host. What works for me under my current environment, may not be the best way for you under your constraints. A general solution to monitoring availability of hosts is non-trivial. And make sure you're not optimizing prematurely.

      The last time I was mucking about with ping, it was on a large scale internal network and I ended up using SNMP gets instead. If you usage needs to be efficient, you might want to look at Net::SNMP as well.