substr outside of string at /usr/local/lib/perl5/5.6.1/sun4-solaris/Net/Ping.pm line 401. Use of uninitialized value in unpack at /usr/local/lib/perl5/5.6.1/sun4-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. #### #!/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 () #{ # 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; }