logo       
Google Custom Search
    AddThis Social Bookmark Button

Component Ping on Windows: msg#00021

Subject: Component Ping on Windows
Can anyone tell me why my WHY DOES THIS NEVER RUN section below does run?  I
want to ping multiple hosts (>1000).  I'm using this to make sure customer
devices that we manage are available.  Using the below, it cycles through
all the hosts but then just sits there.  Also,  many of the pings with this
program fail but if I ping them from a dos prompt they respond just fine.
Any assistance will be greatly appreciated.  Thanks!


use warnings;    # or -w above
use strict;

BEGIN {
    die "POE::Component::Client::Ping requires root privilege\n"
      if $> and ( $^O ne 'VMS' );
}

use POE;
use POE::Component::Client::Ping;
sub PING_TIMEOUT () { 10 }
my $outfile = "/logs/tpaping3.log";
my @pings;

my @addresses = qw(66.94.230.43 198.133.219.25 216.239.57.99);

 POE::Component::Client::Ping->spawn
   ( Alias => 'pinger',
     Timeout => PING_TIMEOUT,
   OneReply => 1
   );

 POE::Session->create
   ( inline_states =>
       { _start => \&client_start,
         pong => \&client_got_pong,
       }
   );

 open (OUT_FH, "> $outfile");
  print OUT_FH "Started ".scalar(localtime)."\n";
 $poe_kernel->run();
 close (OUT_FH);

###########################
# WHY DOES THIS NEVER RUN #
###########################
for (my $xx = 0; $xx <= $#pings; $xx++) {
 print "$pings[$xx][0] $pings[$xx][1] $pings[$xx][2] $pings[$xx][3]\n";
}
exit;

# Event handlers.
sub client_start {
    my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
    print "Starting to ping hosts.\n";
    for (1..20) {
    my $address = shift @addresses;
    last unless defined $address;
        print "Pinging $address at ".scalar(localtime)."\n";
        $kernel->post( pinger => ping => pong => $address );
    }
}

sub client_got_pong {
    my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
    my $request_packet = $_[ARG0];
    my ( $request_address, $request_timeout, $request_time ) =
@{$request_packet};
    my $response_packet = $_[ARG1];
    my ( $response_address, $roundtrip_time, $reply_time ) =
@{$response_packet};
    if ( defined $response_address ) {
   push (my @temp, ip2int($response_address), "CURRENT TIMESTAMP",
int($roundtrip_time * 1000), "U");
   $pings[$#pings+1] = \@temp;
    }
    else {
      print OUT_FH "Timed out waiting for responses from
$request_address.\n";
   push (my @temp, ip2int($request_address), "CURRENT TIMESTAMP", "NULL",
"D");
   $pings[$#pings+1] = \@temp;
    }
  my $address = shift @addresses;
  if (defined $address) {
     print "Pinging $address at ".scalar(localtime)."\n";
     $kernel->post( pinger => ping => pong => $address );
  }
}

sub ip2int($){
  my $ip = shift;
  return unpack("N", pack("C4", split( /\./, $ip)));
}






Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>