| 首页 | 技术文章 | 软件下载 | 博客 | 论坛 | 精品教程 | 黑客动画 | 视频资源 | 在线服务 | 黑客游戏 | 

您现在的位置: 中国X黑客小组 >> 技术文章 >> 编程技术 >> 黑客编程 >> 文章正文 用户登录 新用户注册
  perl多线程处理ping程序          【字体:
perl多线程处理ping程序
作者:Ocean200…    文章来源:CnXHacker.Net    点击数:    更新时间:2007-5-30    
我知道这是个很不优化的程序,但是国内的这方面可以免费得到的资料实在太少了,既然发出来我的代码了,应该有人愿意来帮我改进它吧~?提供建议就非常感谢了:ocean2000@eyou.com
windows系统下运行良好~
-------------------------------------------
以下是代码片段:
#!usr/bin/perl
use warnings;
use strict;
use threads;
$|=1;
my ($startip,$endip,$start,$end,@ip,$a,$div,$c);
print("\nplease enter startip ex:192.168.0.1 :");
chop($startip=<>) ;
if($startip !~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/){
die "Error: the ip is not in format \n";}else{
$start=$4;}
print("\nplease enter endip ex:192.168.0.254 :");
chop($endip=<>);
if($endip !~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/){
die "Error: the ip is not in format \n";}else{
$end=$4;}
for ($a=$start;$a<=$end;$a++){
$ip[$a-$start]="$1.$2.$3.$a";
}
#以上是ip段处理程序

my $thr;
my $ip;
my @ipc=();
my @ip1=();
my @ip2=();
my @ip3=();
my @ip4=();
my @ip5=();
my @ip6=();
my @ip7=();
my @ip8=();
my @ip9=();
my @ip10=();
my @ip11=();
if(($end-$start)<=10){
for($b=0;$b<=1;$b++){
$ip1[$b]=$ip[$b];}
for($b=2;$b<=3;$b++){
$ip2[$b-2]=$ip[$b];}
for($b=4;$b<=5;$b++){
$ip3[$b-4]=$ip[$b];}
for($b=6;$b<=7;$b++){
$ip4[$b-6]=$ip[$b];}
for($b=8;$b<=9;$b++){
$ip5[$b-8]=$ip[$b];}
}
#如果感觉《10没有必要就直接ping吧~
else {
$div=($end-$start)/10;
$div=~/([0-9]).([0-9])/;
$div=$1-1;
print "$div \n";
for($b=0;$b<=$div;$b++){
$ip1[$b]=$ip[$b];}
for($b=0;$b<=$div;$b++){
$ip2[$b]=$ip[$div+$b+1];}
for($b=0;$b<=$div;$b++){
$ip3[$b]=$ip[$div*2+$b+2];}
for($b=0;$b<=$div;$b++){
$ip4[$b]=$ip[$div*3+$b+3];}
for($b=0;$b<=$div;$b++){
$ip5[$b]=$ip[$div*4+$b+4];}
for($b=0;$b<=$div;$b++){
$ip6[$b]=$ip[$div*5+$b+5];}
for($b=0;$b<=$div;$b++){
$ip7[$b]=$ip[$div*6+$b+6];}
for($b=0;$b<=$div;$b++){
$ip8[$b]=$ip[$div*7+$b+7];}
for($b=0;$b<=$div;$b++){
$ip9[$b]=$ip[$div*8+$b+8];}
for($b=0;$b<=$div;$b++){
$ip10[$b]=$ip[$div*9+$b+9];}
$c=$end-$start-$div*10-9;
if($c!=0){
for($b=0;$b<=$c;$b++){
$ip11[$b]=$ip[$div*10+10+$b];
print "$ip11[$b]";}
&ping(@ip11);
}
}
#以上的代码,最恶心了,我测试了很久!一时没有好的办法
#也没有什么参考资料,我的c基础也没有涉及到多线程处理
$thr= threads->new(\&ping,@ip1);sleep 5;
$thr= threads->new(\&ping,@ip2);sleep 5;
$thr= threads->new(\&ping,@ip3);sleep 5;
$thr= threads->new(\&ping,@ip4);sleep 5;
$thr= threads->new(\&ping,@ip5);sleep 5;
$thr= threads->new(\&ping,@ip6);sleep 5;
$thr= threads->new(\&ping,@ip7);sleep 5;
$thr= threads->new(\&ping,@ip8);sleep 5;
$thr= threads->new(\&ping,@ip9);sleep 5;
$thr= threads->new(\&ping,@ip10);sleep 5;
$thr->join;
#如果出现某些threads已经退出,而一些还在运行,请改一下
#sleep设置!
sub ping(){
@ipc=@_;
foreach $ip (@ipc){
system("ping $ip -n 1");
}
}

文章录入:IceRiver    责任编辑:IceRiver 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    Skype蠕虫(w32/Ramex.A)的
    “Skype蠕虫”病毒技术细节
    Skype用户须警惕新Windows蠕
    Skype提醒用户警惕新P2P蠕虫
    US CERT:谷歌eBay雅虎网站均
    Thomson SpeedTouch 2030 SI
    Asterisk 畸形 MIME 数据时有
    Skype登录故障 成全雅虎Mess
    恶意木马变种通过Skype大肆传
    Skype登录故障 微软否认是祸
      网友评论:(只显示最新5条。评论内容只代表网友观点,与本站立场无关!)
    Powered by ICE RIVER - STUDIO
    » CnXHacker.CoM   © CopyRight 2002-2006, CnXHacker.CoM™, Inc. All Rights Reserved.