Lanceo wrote:
> Hi,
>
> I am having difficulty getting the Net::Ping module to work properly. I am
> using ActivePerl 5.6.1.631 on a win32 platform. I can ping a server in a
> dos prompt ok, but when I try to get the Perl Net::Ping to work it always
> returns a failure. It seems to ponder over pinging the host for a couple of
> seconds, and then return a zero as a result, which means that it could not
> reach the host, if my interpretation of the docs is correct.
>
> Here is the snippet in question:
>
> my ($pingThing, $host, $pingResult);
> $host = 'www.google.com';
> $pingThing = Net::Ping->new("tcp", 1);
> $pingResult = $pingThing->ping($host);
>
> print "$pingResult\n";
> if($pingResult == 1){print "$host is alive.\n";}
> else{print "$host could not be pinged\n";}
>
> $pingThing->close();
>
> Am I doing something wrong here, or do I need some other module that I am
> unaware of? I find this sort of bizarre, as I have LWP doing a successful
> page fetch, so the module can obviously access the web.
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.325 / Virus Database: 182 - Release Date: 2/20/02
>
>
>
Here is what I did, as my needs were to explicitly as possible, recreate
the DOS Ping's output.. :)
#***********************************************************
#*
#* This routine will ping that passed hostname, and send its
#* results to the output file...
#*
#***********************************************************
sub ping {
#***********************************************************
#*
#* First we need to re-open the output file, as we closed
#* it after the header was created.
#*
#***********************************************************
open (DUMPFILE,">>$filename");
print DUMPFILE " PINGing $hostname\n";
#***********************************************************
#*
#* ping the hostname
#*
#***********************************************************
@result =`ping $hostname`;
#***********************************************************
#*
#* Output the results of the ping and add the bottom of the
#* pretty border...
#*
#***********************************************************
my $aPing = @result;
my $Pcount = 0;
while ($aPing > 0){
print DUMPFILE "@result[$Pcount]";
$Pcount++;
$aPing --;
}
print DUMPFILE
"******************************************************************** \n";
#***********************************************************
#*
#* Close the output file. This way, if there is a problem,
#* at least the currect results are saved. Leaving it open
#* would allow it to be corrupted, in case of a problem.
#*
#***********************************************************
close (DUMPFILE);
}
I am reading in a list of IPs/URLs via an INI file, and passing the
IP/URL to it...
I need the IPs/URLs elsewhere, so I am using a global declaration... :)
I am sure it could be done easier by making the sub take a parameter,
but I am not at that point in learning Perl yet.. :)
Hope this can help...
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]