in reply to Optimized remote ping

Try Net::Ping in syn/ack mode. With this method you ping all the hosts in the first pass and then gather the responses in the second pass:

# Like tcp protocol, but with many hosts $p = Net::Ping->new( "syn" ); $p->port_number( getservbyname( "http", "tcp" ) ); ### send all the pings first foreach $host ( @host_array ) { $p->ping( $host ); } ### Then check which hosts responded. while( ( $host, $rtt, $ip ) = $p->ack ) { print "HOST: $host [$ip] ACKed in $rtt seconds.\n"; }

In this way, all the delays are overlapped and it reduces the overall runtime significantly.

It is harder to use; so read the docs carefully.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^2: Optimized remote ping (syn/ack)
by themonk (Acolyte) on Jul 17, 2015 at 18:06 UTC

    Hi BrowserUk,

    For my problem, you have hit the solution right on target. I checked the code and its response time is really what i needed. But couldnt understand the below line,

    $p->port_number( getservbyname( "http", "tcp" ) );
    I wanted to check reachability on the port '3000', so i modified it to below line,
    $p->port_number( getservbyname( "3000", "tcp" ) );

    But i think i made some mistake in the parameters as the code is still taking echo port(i.e., 7).

    Please explain me the above line.

    Thanks in advance.

      I got the correct parameters,

      $p->port_number("3000", "tcp");

      Explanation:

      getservbyname function takes the first parameter and sends its defined port to tcp. E.g., "ftp" => 22, "http" => 80 If custom port is to be mentioned, dont use "getservbyname".

      Correct me if my understanding is wrong.

      Thanks guys for all the help. BTW, the response time now is "5secs for 50 IP's" GREAT Response time. :-)