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

I have written a script using Win32::PingICMP and everything seems to working properly. When I use the following address 128.231.013.057 via my script it claims the ping is successful however when I ping it through my machine its unsuccessful. I'm either missing something huge or maybe there is a problem with the module. If anyone can help out it would be greatly appreaciated. Here is my code:
use strict; use warnings; use CGI; use Win32::PingICMP; my $q = new CGI; my %info; foreach my $param ($q->param){ $info{$param} = $q->param($param);} print $q->header(); my $JSCRIPT; my $p = Win32::PingICMP->new(); if ($p->ping($info{ipaddress})) { $JSCRIPT= "alert(\"Ping Successful for " . $p->details->{host} . " +\");\n";} else{ $JSCRIPT = "alert(\"Ping unsuccessful: " . $p->details->{status} . + "\");\n";} $JSCRIPT.= "window.location=\"subnet.pl?subnetid=$info{subnetid}&statu +s_id=$info{status_id}\";"; print $q->start_html(-script => $JSCRIPT); print $q->end_html();

Replies are listed 'Best First'.
Re: Win32::PingICMP returns odd results
by BrowserUk (Patriarch) on Jun 18, 2003 at 16:39 UTC

    The following cut down version of your script (removing the CGI component) seems to function correctly. Maybe you have a down-level version of something?

    #! perl -slw use strict; use Win32::PingICMP; my $p = new Win32::PingICMP; die 'No hosts specified' unless @ARGV; print $_, ' : ', $p->ping( $_ ), ' : ', $p->details->{host}, ' : ', $p +->details->{status} for @ARGV; __END__ D:\Perl\test>ping.exe perlmonks.com Pinging perlmonks.com [209.197.123.153] with 32 bytes of data: Reply from 209.197.123.153: bytes=32 time=280ms TTL=242 Reply from 209.197.123.153: bytes=32 time=261ms TTL=242 Reply from 209.197.123.153: bytes=32 time=250ms TTL=242 Reply from 209.197.123.153: bytes=32 time=251ms TTL=242 D:\Perl\test>ping.exe 128.231.013.057 Pinging 128.231.11.47 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. D:\Perl\test>ping 128.231.013.057 209.197.123.153 "my" variable $count masks earlier declaration in same scope at d:/Per +l/site/lib/Win32/PingICMP.pm line 121. 128.231.013.057 : 0 : 128.231.013.057 : IP_REQ_TIMED_OUT 209.197.123.153 : 1 : 209.197.123.153 : IP_SUCCESS

    The versions I am using are

    D:\Perl\test>perl -mWin32::PingICMP -de1 Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. Win32::API::Type::CODE(0x1b6af60)(d:/Perl/site/lib/Win32/API/Type.pm:4 +0): 40: my $section = 'nothing'; DB<1> M 'AutoLoader.pm' => '5.59 from d:/Perl/lib/AutoLoader.pm' 'Carp.pm' => '1.01 from d:/Perl/lib/Carp.pm' 'Carp/Heavy.pm' => 'd:/Perl/lib/Carp/Heavy.pm' 'Config.pm' => 'd:/Perl/lib/Config.pm' 'DynaLoader.pm' => '1.04 from d:/Perl/lib/DynaLoader.pm' 'Exporter.pm' => '5.566 from d:/Perl/lib/Exporter.pm' 'Term/Cap.pm' => '1.08 from d:/Perl/lib/Term/Cap.pm' 'Term/ReadLine.pm' => '1.00 from d:/Perl/lib/Term/ReadLine.pm' 'Win32/API.pm' => '0.41 from d:/Perl/site/lib/Win32/API.pm' 'Win32/API/Struct.pm' => '0.40 from d:/Perl/site/lib/Win32/API/Struct. +pm' 'Win32/API/Type.pm' => '0.40 from d:/Perl/site/lib/Win32/API/Type.pm' 'Win32/PingICMP.pm' => '0.02 from d:/Perl/site/lib/Win32/PingICMP.pm' 'perl5db.pl' => '1.19 from d:/Perl/lib/perl5db.pl' 'strict.pm' => '1.02 from d:/Perl/lib/strict.pm' 'vars.pm' => '1.01 from d:/Perl/lib/vars.pm' 'warnings.pm' => '1.00 from d:/Perl/lib/warnings.pm' 'warnings/register.pm' => '1.00 from d:/Perl/lib/warnings/register.pm' DB<1>

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Re: Win32::PingICMP returns odd results
by ScooterQ (Pilgrim) on Jun 18, 2003 at 16:48 UTC
    I'm pretty sure it's the format of your address that's the problem. The .013.057 should be .13.57. I hacked up a small section of a script I had hanging around (mine uses Net::Ping instead of Win32PingICMP) and ended up with this:
    use strict; use Net::Ping; my @addresses = ('172.016.016.028', '172.16.16.28'); my $p = Net::Ping->new("icmp", 0.5) or die "Can't create new ping obje +ct: $!\n"; for (@addresses){ if ($p->ping($_)){ print "ping of $_ successful\n"; }else{ print "ping of $_ failed\n"; } } $p->close; _____OUTPUT_____ ping of 172.016.016.028 failed ping of 172.16.16.28 successful
    It's possible that you might get a different result out of Win32::PingICMP, but I doubt it.
      Scooter you were right. It was just the format of the address. Strangley, when I ping the address on my windows box it converts the 128.231.013.057 to 128.231.11.47. Does anyone understand why? Just curious...anyway Thanks!
        windows librarys just ignore the leading 0, whereas on most unix they don't.

        -Waswas
Re: Win32::PingICMP returns odd results
by tedrek (Pilgrim) on Jun 18, 2003 at 16:52 UTC

    Are you running this script on the *same* machine as your manual testing? I ask because of your wording and use CGI. It is possible that one machine can ping a given IP and a different one can't.