Phoenix.pm: Net::Ping Object

Frooninckx Craig - cfroon Craig.Frooninckx at acxiom.com
Tue Feb 5 12:57:13 CST 2002


CONCLUSION:
icmp works, however I have to run the script as root for it to work.  The
default doesn't work even as root, and icmp doesn't work as a user.  I still
feel like something is missing, but that hunt can wait for another day (bah
haha).

-----Original Message-----
From: Scott Walters [mailto:phaedrus at illogics.org]
Sent: Tuesday, February 05, 2002 10:48 AM
To: 'phoenix-pm-list at happyfunball.pm.org'
Subject: Re: Phoenix.pm: Net::Ping Object



Net::Ping uses UDP by default. Real pings are ICMP (Internet Control
Message Protocol). Is the machine running a firewall that discards
UDP packets?


>From the docs:

   Net::Ping->new([$proto [, $def_timeout [, $bytes]]]);
          Create a new ping object. All of the parameters are optional.
          $proto specifies the protocol to use when doing a ping. The
          current choices are "tcp", "udp" or "icmp". The default is 
          "udp".

so, you prolly want:
my $ping = new Net::Ping qw(icmp);

or something similiar...

goodluck!
-scott

On Tue, 5 Feb 2002, Frooninckx Craig - cfroon wrote:

> I've written a small application that is suppose to go out and ping a
server
> to verify that the network is still active between the local server and
the
> remote server.  When I do a command line ping it works fine, however, when
I
> use the Net::Ping object, it reports that it is unable to access the
remote
> server (in the code the remote server is actually the localserver).  Can
> anyone see the bug??
> 
> -Craig
> 
> 
> SOURCE CODE:
> #!/usr/bin/perl -w
> 
> # Application to check the availibility of production servers every hour.
> 
> use strict;
> 
> use Net::Ping;
> use Date::Format;
> 
> while () {
>         my $p = Net::Ping->new() or die "Can't create ping: $!\n";
>         my $time = time2str( "%X", time );
>         print "\nTime: $time\n";
>         my $host = "127.0.0.1";
>         print "Ping: ", $p->ping( $host ), "\n";
>         print "$host is responding!\n" if $p->ping( $host );
>         $p->close;
>         sleep 60;
> };
> 
> __END__
> 
> RESULTS:
> cfroon at gsgatlas: /usr/users/cfroon/Perl => ping.pl      
> 
> Time: 10:32:20
> Ping: 0
> cfroon at gsgatlas: /usr/users/cfroon/Perl => ping 127.0.0.1
> PING 127.0.0.1 (127.0.0.1): 56 data bytes
> 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0 ms
> 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0 ms
> 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0 ms
> 
> 
> ----127.0.0.1 PING Statistics----
> 3 packets transmitted, 3 packets received, 0% packet loss
> round-trip (ms)  min/avg/max = 0/0/0 ms
> 
> 
> ********************************************************************
> 
> The information contained in this communication is
> confidential, is intended only for the use of the recipient
> named above, and may be legally privileged.
> If the reader of this message is not the intended
> recipient, you are hereby notified that any dissemination, 
> distribution, or copying of this communication is strictly
> prohibited.
> If you have received this communication in error,
> please re-send this communication to the sender and
> delete the original message or any copy of it from your
> computer system. Thank You.
> 
> 



More information about the Phoenix-pm mailing list