in reply to Re^2: Net::ping is very unstable
in thread Net::ping is very unstable

The ping command sends ICMP packets. Your code sends SYN packets and expects ACK replies.

I recommend you consult with your network administrator how to best check the connectivity between hosts on your network.

Replies are listed 'Best First'.
Re^4: Net::ping is very unstable
by hxbsy (Novice) on Apr 09, 2015 at 12:10 UTC

    I see.but I use "Net::Ping->new('icmp');",the script runs very slowly.
    in fact I check whether remote host opens specific port or not.for speed,I first have to use "Net::Ping" to check the host is alive or not.
    Can you give better advice?

        #!/usr/bin/perl -w #use strict; use warnings; use IO::Handle; use Socket; use threads; use IO::Socket::INET; use Net::Ping; open(pctxt,'./pc.txt')||die "error open $!"; open(pc_log, ">./pclog.txt")||die "error open $!"; my $stime = time; while($read_data = <pctxt>) { #chomp; $read_data=~s/\s//g; $read_data=~s/" "//g; thread($read_data); } my $etime = time; my $diff = $etime-$stime; print "$diff \n"; close(pc_log); close(pctxt); ########################################## sub thread { my $net = shift; my @ip = (1..255); my $port = 12345; my $thr0 = threads->new(\&scan, $net,@ip[0..15]); my $thr1 = threads->new(\&scan, $net,@ip[16..31]); my $thr2 = threads->new(\&scan, $net,@ip[32..47]); my $thr3 = threads->new(\&scan, $net,@ip[48..63]); my $thr4 = threads->new(\&scan, $net,@ip[64..79]); my $thr5 = threads->new(\&scan, $net,@ip[80..95]); my $thr6 = threads->new(\&scan, $net,@ip[96..111]); my $thr7 = threads->new(\&scan, $net,@ip[112..127]); my $thr8 = threads->new(\&scan, $net,@ip[128..143]); my $thr9 = threads->new(\&scan, $net,@ip[144..159]); my $thr10 = threads->new(\&scan, $net,@ip[160..175]); my $thr11 = threads->new(\&scan, $net,@ip[176..191]); my $thr12 = threads->new(\&scan, $net,@ip[192..207]); my $thr13 = threads->new(\&scan, $net,@ip[208..223]); my $thr14 = threads->new(\&scan, $net,@ip[224..239]); my $thr15 = threads->new(\&scan, $net,@ip[240..254]); $thr0->join(); $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); $thr6->join(); $thr7->join(); $thr8->join(); $thr9->join(); $thr10->join(); $thr11->join(); $thr12->join(); $thr13->join(); $thr14->join(); $thr15->join(); } sub scan { my ($net,@ip) = @_; foreach my $ip (@ip) { $host ="$net$ip"; if (Is_Host_Alive($host)) { my $socket = new IO::Socket::INET( PeerHost =>$host, PeerPort =>'12345', Proto =>'tcp' );# or die "ERROR in Socket Creation : $!\n"; if (($socket) && scan700($host)) { print "$host not shutdown \n"; } } # $socket->close(); } } sub scan700 { my ($ip) = @_; $host = "$ip"; my $socket = new IO::Socket::INET( PeerHost =>$host, PeerPort =>'700', Proto =>'tcp' );# or die "ERROR in Socket Creation : $!\n"; if($socket) { print "$host is ATM \n"; return 0; } #$socket->close(); return 1; } sub Is_Host_Alive { my ($host) = @_; my $tmp_icmp=Net::Ping->new('icmp'); if(!$tmp_icmp->ping($host)) { #print "$host ping unreachable \n"; $tmp_icmp->close; return 0; } $tmp_icmp->close; return 1; }

        "pc.txt" file as following:
        192.168.1.
        192.168.2.
        .....
        192.168.150.
        I want to check that whether so many net's hosts have been opened by port 12345 and not by port 700 or not.
        Can you give me better advice for the result?