spickles has asked for the wisdom of the Perl Monks concerning the following question:

I used some code from a writer in the Linux Journal magazine to begin to understand Net::Ping. I would like to monitor my switch as it reboots, and then alert the user with a popup when it is back online. I used the code below, and it still reports the host unavailable despite the fact that I was able to ping it before and immediately after running this code:

#!/usr/bin/perl -w use strict; use Net::Ping; my $host = $ARGV[0]; my $p = Net::Ping->new("icmp"); if ($p->ping($host)) { print "$host is alive.\n"; } else { print "$host is not reachable.\n"; }


Cheers,
Scott

Replies are listed 'Best First'.
Re: Net::Telnet Question
by jethro (Monsignor) on Jul 24, 2008 at 03:02 UTC
    The code is working fine here, just needed root privileges (but it said so in an error message). Did you check that the switch can be pinged at all?

Re: Net::Telnet Question
by Khen1950fx (Canon) on Jul 24, 2008 at 05:38 UTC
    You could use the external protocol such that:

    #!/usr/bin/perl use strict; use warnings; use Net::Ping::External qw(ping); my $alive = ping(host => "127.0.0.1"); print "127.0.0.1 is online\n" if $alive;
Re: Net::Telnet Question
by Bloodnok (Vicar) on Jul 24, 2008 at 09:36 UTC
    Are you absolutely sure your host should be responding to ICMP ping requests - Net::Ping also supports pinging via TCP & UDP.
    Also, is there a firewall between you and the host configured to disallow any ping requests - most frequently ICMP packets?

    HTH,

    At last, a user level that overstates my experience :-))
      Bloodnok -

      I'll have to look at the other ping options. I am using it with the default. I was able to ping from a cmd prompt before and after the script. Thanks for the ideas.

      Regards,
      Scott