#!/usr/bin/perl # isalive6.pl is provided by Ph03n1X # I use fork() to simplify this code even it is not as effective # as using threading in memory. use strict; use warnings; use Switch; use POSIX; my $LOGFILE = "./logs/isalive6.log"; my $MAX_CHILD = 100; MAIN: { my @IPV6LIST; if(!$ARGV[0]){ print "usage : run \n"; exit; } open(LIST,"<$ARGV[0]") or die(); chop(@IPV6LIST=); my $len = @IPV6LIST; my $i = 0; my $j = 0; while ($j < $len){ switch (fork()){ case (0) { doping6($j+1,$IPV6LIST[$j]);_exit(0); } case (-1) { print "Can not fork!\n";_exit(-1); } else { if($i>$MAX_CHILD-2){ wait();$i--; } } } $i++;$j++; } print "Total Host Scanned : " . $len . "\n"; close(LIST); } sub doping6 { my($tid,$ipv6host)=@_; open(OFILE,">>$LOGFILE"); my @pinglist = `ping6 -c2 -s 0 $ipv6host`; my $result = "@pinglist"; if($result =~ m/8 bytes from/){ print $tid . " : [REACHED] " . $ipv6host . "\n"; print OFILE "[REACHED]" . $ipv6host . "\n"; }else{ print $tid . " : [NOT REACHED] " . $ipv6host . "\n"; } close(OFILE); }