TestPort 1.0 用perl寫的來測試端口的小程序

TestPort 1.0  用perl寫的來測試端口的小程序
By pchoer 03/24/2006

這個程序是一直測試某IP的某個端口的關/閉情況的,類似於ping IP -t。(ping是對IP,我這個是對port)。
因爲在實際應用中,有時會用到這樣的功能,所以寫了這個小程序,測試時方便些。      
 Usage:tp.exe host port
    Exp:tp.exe 192.168.0.1 80

代碼如下::

#!/usr/bin/perl -w
#TestPort 1.0
#By pchoer 03/24/2006;

use IO::Socket;
use Net::Ping;

if (@ARGV != 2) {
 print "TestPort 1.0 /nBy pchoer 03//24//2006/n";
 print "/n/tUsage=>$0 host port/n";exit 1;
    }
else
{
 chomp($ARGV[0]);chomp($ARGV[1]);
    $host=$ARGV[0];$port=$ARGV[1];
$p=Net::Ping->new();$alive=$p->ping($host);
if ($alive) {
 print "TestPort 1.0 /nBy pchoer 03//24//2006/n";
  again:
  $sock=IO::Socket::INET->new(PeerAddr=>$host,PeerPort=>$port,Timeout=>30);

  if ($sock) {
   print "/n$host:$port is 【Open】.";close $sock;
   select undef,undef,undef,1;
            }
  else
  {
  print "/n×××××/[$host:$port is Close!/]";
  }

  goto again;
 }#alive

else {

print "/nError::Can't Connect $host!!Please Make Sure $host is availability./n";exit 1;
}

}

軟件下載:http://www.06second.com/pchoer/soft/tp.rar

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章