Ping.pm是否能实现端口扫描

Ping.pm是否能实现端口扫描

我查看http://search.cpan.org/~bbb/Net-Ping-2.31/lib/Net/Ping.pm
我的代码:

[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/perl -w
#scan the host's port open or not open

use strict;

use Net::Ping;

my $dst_ip=$ARGV[0];
my $start_port=$ARGV[1];
my $end_port=$ARGV[2];
my $scan=undef;

sub Usage(){
        print "Usage:perl sacn_prot.pl ipaddr start_port end_port\n";
        print "For Example: perl scan_port.pl 127.0.0.1 0 65535\n";
        print "**NOTE**:The ipaddr arg must be a numeric value,like 127.0.0.1\n";
        print "Good Luck!\n";
}

{
        if(!defined $ARGV[0]){
                Usage();
                exit 0;
        }

        if($dst_ip =~ /(\d+).(\d+).(\d+).(\d+)/){
                for(my $pt_num=$start_port;$pt_num <= $end_port;$pt_num++){
                        $scan=Net::Ping->new("syn");
                        $scan->{port_num}=$pt_num;
                        $scan->ping($dst_ip);
                        print "Scaning ......\n";
                        if($scan->ack){
                                print "Port:$pt_num is opening!\n";
                                $scan->close;
                                next;
                        }
                        $scan->close;
                }
        }else{
                Usage();
                exit 0;
        }

        print "\n"."Scan Action is over!\n";
        exit 0;

测试发现:每个端口扫描的结果都是open.

查看Ping.pm,没有看到syn可以实现扫描端口,请各位指教一下

[Copy to clipboard] [ - ]
CODE:
If the "syn" protocol is specified, the ping() method will only send a TCP SYN packet to the remote host then immediately return. If the syn packet was sent successfully, it will return a true value, otherwise it will return false. NOTE: Unlike the other protocols, the return value does NOT determine if the remote host is alive or not since the full TCP three-way handshake may not have completed yet. The remote host is only considered reachable if it receives a TCP ACK within the timeout specifed. To begin waiting for the ACK packets, use the ack() method as explained below. Use the "syn" protocol instead the "tcp" protocol to determine reachability of multiple destinations simultaneously by sending parallel TCP SYN packets. It will not block while testing each remote host. demo/fping is provided in this distribution to demonstrate the "syn" protocol as an example. This protocol does not require any special privileges.

If the "syn" protocol is specified, the ping() method will only send a TCP SYN packet to the remote host then immediately return.

Unlike the other protocols, the return value does NOT determine if the remote host is alive or not since the full TCP three-way handshake may not have completed yet.

文档写的清楚得不能再清楚了


QUOTE:
原帖由 Nosferatu 于 2008-5-11 08:15 发表
If the "syn" protocol is specified, the ping() method will only send a TCP SYN packet to the remote host then immediately return.

Unlike the other protocols, the return value does NOT determin ...

不是很明白你的意思。我从上面的文字中理解出来的意思是发syn并不能诊断其指定的端口是否打开。