Phoenix.pm: Net::Ping Object
David A. Sinck
sinck at ugive.com
Tue Feb 5 12:06:22 CST 2002
You might need root to do it; ping is suid.
\_ SMTP quoth Frooninckx Craig - cfroon on 2/5/2002 10:36 as having spake thusly:
\_
\_ 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