- 主题
- 0
- 积分
- 0
- 贝壳
- 0 个
- 注册时间
- 2007-1-18
- 最后登录
- 2007-1-18
|
[原创]自己用perl写的很不成熟的一段图形界面的端口扫描程序代码
[这个贴子最后由damnyou在 2006/11/29 11:57pm 第 2 次编辑]
- #!c:\perl\perl.exe -w
- use Tk;
- use IO::Socket::INET;
- use Net::Ping;
- use encoding ';euc-cn';, STDIN => ';euc-cn';, STDOUT => ';euc-cn';;
- require Tk::ProgressBar;
- #use Win32::Process;
- my $portlist="21,23,25,80,135,139,3389";
- my $str=';127.0.0.1';;
- my $value=';cy';;
- my $conn=';tcp';;
- my $percent_done=0;
- $connn=0;
- my $cportc=0;
- my $cport=0;
- $|=1;
- open(IEP,';echo %SystemDrive% |';);
- $iepath=<IEP>;
- chomp($iepath);
- my $iestr=';R0lGODlhuAEoAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgMDAwP8AAAD/AP//AAAA//8A/wD/
- /////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMwAAZgAAmQAAzAAA/wAzAAAzMwAzZgAzmQAzzAAz/wBm
- AABmMwBmZgBmmQBmzABm/wCZAACZMwCZZgCZmQCZzACZ/wDMAADMMwDMZgDMmQDMzADM/wD/AAD/
- MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMzADMzMzMzZjMzmTMzzDMz/zNmADNmMzNm
- ZjNmmTNmzDNm/zOZADOZMzOZZjOZmTOZzDOZ/zPMADPMMzPMZjPMmTPMzDPM/zP/ADP/MzP/ZjP/
- mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2YzAGYzM2YzZmYzmWYzzGYz/2ZmAGZmM2ZmZmZmmWZm
- zGZm/2aZAGaZM2aZZmaZmWaZzGaZ/2bMAGbMM2bMZmbMmWbMzGbM/2b/AGb/M2b/Zmb/mWb/zGb/
-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:
- my $mw=MainWindow->new or die ';Err!';;
- $mw->title(';Port Scanner By Xtiger www.Xtiger.net&www.ThySea.com';);
- $mw->geometry("450x365");
- $mw->maxsize(450,365);
- my $image=$mw->Photo(-data =>';R0lGODlhDQAPALMAAP//////AMzMzJmZmZmZAGZmZjOZ/wCZzAAA/wAAzAAAmQAAAP///wAAAAAA
- AAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFFAAMACwAAAAADQAPAAAERJCxQWuVE+gNRFnSACxk
- 6YHZciCJogxfOCa0e8qL0rZ36v69QWlI+og4SGNHwBSYPgWLtBAjWjFYIXZiIXgXFmLgO4wAACH5
- BAkUAAwALAAAAAANAA8AAAQVkMlJq734mr0x79rniVlpnmiqrlcEADs=';);
- my $image1=$mw->Photo(-data =>';R0lGODlhDQAPALMAAP//////AMzMzJmZmZmZAGZmZjOZ/wCZzAAA/wAAzAAAmQAAAP///wAAAAAA
- AAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFFAAMACwAAAAADQAPAAAERJCxQWuVE+gNRFnSACxk
- 6YHZciCJogxfOCa0e8qL0rZ36v69QWlI+og4SGNHwBSYPgWLtBAjWjFYIXZiIXgXFmLgO4wAACH5
- BAkUAAwALAAAAAANAA8AAAQVkMlJq734mr0x79rniVlpnmiqrlcEADs=';,-palette =>100);
- $mw->Photo(';imageweb';,-data =>$iestr);
- my $enhost=$mw->Label(-text=>';目标主机:';)->place(-x=>20,-y=>45);
- my $ent=$mw->Entry(-width=>40,-textvariable=>\$str)->place(-x=>120,-y=>45);
- my $run=$mw->Button(-command=>[\&run],-text=>';扫 描';,-height => 1,-width => 4)->place(-x=>370,-y=>42);
- my $exx=$mw->Button(-command=>[\&exx],-text=>';退 出';,-height => 1,-width => 4)->place(-x=>410,-y=>42);
- my $web=$mw->Button(-command=>[\&web],-image => ';imageweb';,-height => 35,-width => 441,-borderwidth=>1)->place(-x=>2,-y=>0);
- my $yj=$mw->Radiobutton(-text=>';常用端口';,-variable=>\$value,-value=>';cy';)->place(-x=>20,-y=>65);
- my $entport=$mw->Entry(-width=>50,-textvariable=>\$portlist)->place(-x=>120,-y=>65);
- my $zj=$mw->Radiobutton(-text=>';自定义端口';,-variable=>\$value,-value=>';dy';)->place(-x=>20,-y=>85);
- my $entstartport=$mw->Entry(-width=>10,-textvariable=>\$startport)->place(-x=>120,-y=>85);
- my $enz=$mw->Label(-text=>';至';)->place(-x=>200,-y=>85);
- my $entendport=$mw->Entry(-width=>10,-textvariable=>\$endport)->place(-x=>240,-y=>85);
- my $rtcp=$mw->Radiobutton(-text=>';TCP连接模式';,-variable=>\$conn,-value=>';tcp';)->place(-x=>90,-y=>110);
- my $rsyn=$mw->Radiobutton(-text=>';SYN连接模式';,-variable=>\$conn,-value=>';syn';)->place(-x=>280,-y=>110);
- my $frame=$mw->Frame();
- my $probar=$frame->ProgressBar(
- -borderwidth => 1,
- -width => 6,
- -length =>340,
- -anchor => ';w';,
- -from => 0,
- -to => 100,
- -blocks => 1,
- -colors => [0,';skyblue';,20,';green';,40,';blue';,60,';yellow';,80,';red';],
- -variable => \$percent_done)->pack();
- $frame->place(-x=>40,-y=>135);
- my $stdout=$mw->Scrolled(';Text';,-scrollbars=>';e';,-height=>15,-width=>60)->place(-x=>0,-y=>145);
- $stdout->configure(-background=>';dimgray';,-borderwidth => 3,);
- $t = $stdout->Subwidget(';scrolled';);
- $t->tagConfigure(';close';, -foreground => ';green';);
- $t->tagConfigure(';open';, -foreground => ';red';);
- $t->tagConfigure(';other';, -foreground => ';cyan';);
- sub run
- {
- $cportc=0;
- $ent->configure(qw/-state disabled/);
- $run->configure(qw/-state disabled/);
- $yj->configure(qw/-state disabled/);
- $entport->configure(qw/-state disabled/);
- $zj->configure(qw/-state disabled/);
- $entstartport->configure(qw/-state disabled/);
- $entendport->configure(qw/-state disabled/);
- $rsyn->configure(qw/-state disabled/);
- $rtcp->configure(qw/-state disabled/);
- my $host=$str;
- if($value eq "dy")
- {
- $mw->messageBox(qw/-icon error -title 错误! -type OK -message/ => "请指定端口范围!") and goto END if($startport eq "" or $endport eq "");
- @port=($startport..$endport);
- }
- if($value eq "cy")
- {
- $mw->messageBox(qw/-icon error -title 错误! -type OK -message/ => "请指定端口列表(用逗号隔开)!") and goto END if $portlist eq "";
- @port=split(/,/,$portlist);
- }
- $stime=time;
- $cport=scalar(@port);
- if($conn eq "tcp")
- {
- foreach(@port) {
- $connn++;
- if($connn%2==0){$conico=$mw->Label(-image => $image,-height => 30,-width => 30)->place(-x=>0,-y=>110);}
- if($connn%2!=0){$conico=$mw->Label(-image => $image1,-height => 30,-width => 30)->place(-x=>0,-y=>110);}
- $mw->update;
- if(my $sock = IO::Socket::INET->new(PeerAddr => $host,
- PeerPort => $_,
- Proto => ';tcp';)
- )
- {
- my $restr="[开放] $host:$_\n";
- $t->insert(';end';, "$restr", ';open';);
- }
- else
- {
- my $restr="[关闭] $host:$_\n";
- $t->insert(';end';, "$restr", ';close';);
- }
- $cportc++;
- $percent_done=int(($cportc/$cport)*100);
- my $zstr="$cportc/$cport";
- my $zt=$mw->Label(-textvariable=>\$zstr)->place(-x=>405,-y=>125);
- $mw->update;
- }
- }
- if($conn eq "syn")
- {
- foreach my $port (@port) {
- $connn++;
- if($connn%2==0){$conico=$mw->Label(-image => $image,-height => 30,-width => 30)->place(-x=>0,-y=>110);}
- if($connn%2!=0){$conico=$mw->Label(-image => $image1,-height => 30,-width => 30)->place(-x=>0,-y=>110);}
- $mw->update;
- $p = Net::Ping->new("syn");
- $p->{port_num} =$port;
- $p->ping($host);
- if($p->ack)
- {
- my $restr="[开放] $host:$port\n";
- $t->insert(';end';, "$restr", ';open';);
- }
- else
- {
- my $restr="[关闭] $host:$port\n";
- $t->insert(';end';, "$restr", ';close';);
- }
- }
- $cportc++;
- $percent_done=int(($cportc/$cport)*100);
- my $zstr="$cportc/$cport";
- my $zt=$mw->Label(-textvariable=>\$zstr)->place(-x=>405,-y=>125);
- $mw->update;
- }
- $etime=time;
- $ttime=$etime-$stime;
- my $restr="------------------------------\n扫描完成耗时 $ttime 秒!\n";
- $t->insert(';end';, "$restr", ';other';);
- END:
- $ent->configure(qw/-state normal/);
- $run->configure(qw/-state normal/);
- $yj->configure(qw/-state normal/);
- $entport->configure(qw/-state normal/);
- $zj->configure(qw/-state normal/);
- $entstartport->configure(qw/-state normal/);
- $entendport->configure(qw/-state normal/);
- $rtcp->configure(qw/-state normal/);
- $rsyn->configure(qw/-state normal/);
- }
- sub web
- {
- #Win32::Process::Create(my $ProcessObj,
- # qq/$iepath\\Intern~1\\iexplore.exe/,
- # "iexplore.exe http://www.xtiger.net",
- # 0,
- # NORMAL_PRIORITY_CLASS,
- # ".")|| die "$!\n";
- system("$iepath\\Progra~1\\Intern~1\\iexplore.exe http://www.xtiger.net");
- $mw->update;
- }
- sub exx
- {
- exit;
- }
- MainLoop;
复制代码 |
|