为什么会这样????/
为什么会这样????/
$f=1;
$k=1024;
foreach $IPaddr(@xx){
($name,$aliases,$type,$len,$thataddr)=gethostbyname($IPaddr);
foreach $port($f..$k){
$this=pack($sockaddr,$AF_INET,0,$thataddr);
$that=pack($sockaddr,$AF_INET,$port,$thataddr);
die "unknown host $IPaddr\n" if($thataddr eq "");
push(@IPaddr1,$IPaddr);
push(@port1,$port);
push(@this1,$this);
push(@that1,$that);
};
};
my $portend=0;
for(;$portend<=@port1;){
if(@port1<=10){
for($i=0;$i<=@port1;$i++){
$IPaddr2=@IPaddr1[$portend];
$port2=@port1[$portend];
$this2=@this1[$portend];
$that2=@that1[$portend];
$portend++;
$threads[$i]=threads->new(\&scan1,$this2,$that2,$port2,$IPaddr2);
$hisid1=$threads[$i]->tid();
print "正在开始线程$hisid1\n";
#print "$threads[$i]=threads->new(\&scan1,$this2,$that2,$port2)\n";
}
}
elsif(@port1>=10){
for($port3=10;$port3<=@port1;$port3=$port3+10){
for($i=0;$i<=10;$i++){
$IPaddr2=@IPaddr1[$portend];
$port2=@port1[$portend];
$this2=@this1[$portend];
$that2=@that1[$portend];
$threads[$i]=threads->new(\&scan1,$this2,$that2,$port2,$IPaddr2);
$hisid1=$threads[$i]->tid();
print "正在开始线程$hisid1\n";
#push(@threads1,$threads[$i]);
$portend++;
#print "$threads[$i]=threads->new(\&scan1,$this2,$that2,$port2)\n";
$port4=@port1-$port3;
}
for($n=0;$n<$i;$n++){
print "正在结束线程$n\n";
$threads[$n]->join();
};
# foreach $n(@threads1){
#print "正在结束线程$n\n";
#$n->join;
#}
#splice(@threads1,0);
}
for($i=0;$i<=$port4;$i++){
$IPaddr2=@IPaddr1[$portend];
$port2=@port1[$portend];
$this2=@this1[$portend];
$that2=@that1[$portend];
$threads[$i]=threads->new(\&scan1,$this2,$that2,$port2,$IPaddr2);
# $hisid1=$threads[$i]->tid();
#print "正在开始线程$hisid1\n";
$portend++;
#print "$threads[$i]=threads->new(\&scan1,$this2,$that2,$port2)\n";
}
}
for($n=0;$n<$i;$n++){
# print "正在结束线程$n\n";
$threads[$n]->join();
};
}
#检测开放的端口并显示端口上运行的任务
sub scan1{
#print "$port2";
my $th_is=shift;
my $th_at=shift;
my $po_rt=shift;
#Thread->self->detach;
socket(S,$AF_INET,$SOCK_STREAM,$proto) or die $!;
#bind(S,$th_is) or die $!;
if(connect(S,$th_at)){
($srv_name,$srv_aliases,undef,undef)=getservbyport($po_rt,'tcp');
print "检测到$IPaddr2开放端口:";
printf("%5d %s\n",$port2,$srv_name||"unknown serv");
close(S);
return;
};
};
为什么运行时要占用那么大的CPU和内存啊,请教各位老大指点我一个改决的方法啊?请帮帮忙啊[CCB]10[/CCB][CCB]10[/CCB][CCB]10[/CCB]