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;
}
}