substr outside of string at /usr/local/lib/perl5/5.6.1/sun4-solaris/Ne +t/Ping.pm line 401. Use of uninitialized value in unpack at /usr/local/lib/perl5/5.6.1/sun +4-solaris/Net/Ping.pm line 401. Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/ +5.6.1/sun4-solaris/Net/Ping.pm line 406.
I get this every time I pass in the IP address of the box running the code. So far I have been able to run correctly on every IP I have tried. If I pass it the loopback IP or the local IP it errors. I have moved the code to another box and set it up to use the local IP address of that box and it worked fine.
The box on which it works is a 5.8.0 installation and the one where it dosen't is a 5.6.1. I would attribute the problem to that normally, but I'm not sure. The Net::Ping is exactly the same. The new box didn't even have it so I just copied the directory from my box where it failed to the test box and all works fine.
As you can see, I commented out the section where it reads the IP addresses from a file for testing, the problem happens either way.
Could someone shed some light on what may be going on? Here is the code I'm using:
#!/usr/bin/perl -w use strict; use IO::Handle; use Net::Ping; use Net::SNMP; use Data::Dumper; my $source_file = (shift || "/tmp/ping_list.txt"); my %pid_to_host; my %host_result; my @hosts; my $OID = '.1.3.6.1.4.1.15102'; #open(IPS,"$source_file") # or die "Cannot open source file $source_file: $!\n"; autoflush STDOUT 1; #for (<IPS>) #{ # chomp; # s/ *//; # s/\cM//; # if ($_ =~ m/^\d+\.\d+\.\d+\.\d+$/) # { # push(@hosts,$_); # } # else # { # print BAD "$_ : NOT A VALID IP ADDRESS\n"; # } #} $hosts[0] = '10.51.8.109'; $hosts[1] = '127.0.0.1'; for (@hosts) { wait_for_a_kid() if keys %pid_to_host > 10; if ( my $pid = fork ) { # parent $pid_to_host{$pid} = $_; } else { # child exit ping_a_host($_); } } 1 while wait_for_a_kid(); sub ping_a_host { my $host = shift; my $p = Net::Ping->new('icmp',2); print "yes\n" if $p->ping($host) ? 1 : 0; #`/usr/sbin/ping -n $host 1 2>/dev/null` =~ /no answer from/ ? +0 : 1; } sub wait_for_a_kid { my $pid = wait; return 0 if $pid < 0; my $host = delete $pid_to_host{$pid} or warn("Why did I see $pid ($?)\n"), next; print "send_trap('ncool1','public','162',$host,$OID)\n" if (!$?) +; 1; } sub send_trap { my ($host, $community, $port, $ipAddr, $OID) = (@_); my ($session, $error) = Net::SNMP->session( -hostname => shift || $host, -community => shift || $community, -port => shift || $port ); if (!defined($session)) { exit 1; } my $result = $session->trap( -enterprise => $OID, -generictrap => 2, -specifictrap => 9999, -varbindlist => [$OID,OCTET_STRING,$ipAddr] ); if (!defined($result)) { $session->close; exit 1; } $session->close; exit 0; }
In reply to Net::Ping Problem with local IP by gnu@perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |