#!/usr/bin/perl # Port scanner tcpscan6.pl coded by Ph03n1X #cpan IO::Socket::INET6 use IO::Socket::INET6; use Getopt::Long; use strict; use warnings; use Switch; use POSIX; my $MAX_CHILD = 50; my $LOGFILE = "tcpscan6.log"; my $i=0; sub doTcpscan6 { my ($host,$port) = @_; open (WFILE,">>$LOGFILE"); my $s = IO::Socket::INET6->new(PeerAddr => $host, PeerPort => $port, Domain => AF_INET6, Timeout => 5); if($s){ print "[OPEN] $host on $port\n"; print WFILE "[OPEN] $host on $port\n"; }else{ print "[CLOSE/FIREWALL] $host on $port\n"; } close(WFILE); } sub doFork { my ($host,$port,$count) = @_; switch(fork()){ case (0) { doTcpscan6($host,$port);_exit(0); } case (-1) { print "Can not fork!\n";_exit(-1); } else { if($port>$MAX_CHILD-2){ wait();$count--; } } } } sub usage { print " TCP IPv6 Scanner Usage : [--help|-h] - This help [--target|-t] - Target single IPv6 address [--in-file|-i] - Target list of IPv6 address in file [--port|-p] - Target port. Multiple ports separated by comma [--range|-r] - Target range port. Ex : 100-200 \n"; } MAIN: { my @IPV6LIST; if(!$ARGV[0]){ usage(); exit; } my ($help,$target,$infile,$mport,$rport); GetOptions( 'help' => \$help, 'target=s' => \$target, 'in-file=s' => \$infile, 'port=s' => \$mport, 'range=s' => \$rport, ) or die "Invalid options!! Try --help for details.\n"; if($help){ usage(); exit; } if($target && $infile){ print "ERROR! Can not use [--target|-t] with [--in-file|-i]\n"; exit; } if($mport && $rport){ print "ERROR! Can not use [--port|-p] with [--range|-r]\n"; exit; } my $count=1; if($target){ if($target =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/){ print $target . "is not valid IPv6 address!\n"; exit; } if($mport){ my @allport = split(',',$mport); foreach my $port (@allport){ doFork($target,$port,$count); $count++; } } if($rport){ my @allport = split('-',$rport); my $lowport = $allport[0]; my $highport = $allport[1]; if($lowport>$highport){ print "ERROR! Left port must be lower than in the right!\n"; exit; } for(my $i=$lowport;$i<=$highport;$i++){ doFork($target,$i,$count); $count++; } } } if($infile){ open(RFILE,"<$infile") or die(); chop(@IPV6LIST=); my $len = @IPV6LIST; my $j=0; for($j=0;$j<$len;$j++){ if($IPV6LIST[$j] =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/){ print $IPV6LIST[$j] . "is not valid IPv6 address!\n"; exit; } if($mport){ my @allport = split(',',$mport); foreach my $port (@allport){ doFork($IPV6LIST[$j],$port,$count); $count++; } } if($rport){ my @allport = split('-',$rport); my $lowport = $allport[0]; my $highport = $allport[1]; if($lowport>$highport){ print "ERROR! Left port must be lower than in the right!\n"; exit; } for(my $k=$lowport;$k<=$highport;$k++){ doFork($IPV6LIST[$j],$k,$count); $count++; } } } close(RFILE); } #end if infile }