The following is the code I use to verify if a system is reachable before I
perform other actions on it. I have used it in several scripts and it works
as advertised.
Assume the script has use Net::Ping and also has defined the IP address of
the system you are trying to reach as '$Destination' -
<code>
sub VerifyConnectivity {
# This subroutine tries to ping the destination server.
# If it fails, the program exits.
SWITCH: {
$response = Net::Ping->new("icmp");
if($response->ping($Destination)) { $response->close(); last
SWITCH; }
$response = Net::Ping->new("udp");
if($response->ping($Destination)) { $response->close(); last
SWITCH; }
die "\n$Destination is unreachable: $!\n"; } # end of SWITCH
print "\nI was able to ping the server at $Destination.\n";
} # end of sub VerifyConnectivity
</code>
> -----Original Message-----
> From: Gary MacDonald [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 30, 2001 08:49 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Problem with PING method
>
> The documentation for Net::Ping doesn't suggest that an IP address string
> (e.g., '192.168.1.1') has to be converted to a thirty-two bit integer.
> Just use the IP address string (or a scalar containing the string):
>
> print "Host is alive" if $p->ping('192.168.1.1');
>
> Net::Ping doesn't work with the loopback address on my machine, but it
> does work for a real IP address string.
>
>
> Gary
>
> -----Original Message-----
> From: Roboz Béla [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 30, 2001 5:00 AM
> To: [EMAIL PROTECTED]
> Subject: Problem with PING method
>
>
>
> Hi All,
>
> Please help me, Why the ping method in the prg. doesn't return a true
> value? I don't understand it.
>
> Thanks: Beci
>
>
> _____
>
> #!/usr/bin/perl -w
> use Socket;
> use Net::Ping;
>
> $iaddr=inet_aton("127.0.0.1"); # or other address
>
> $p = Net::Ping->new();
> print "Host is alive" if $p->ping($iaddr);
> $p->close();
> _____
>
>
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin