in reply to Multi-threading ping of a list of hosts.....Again!

Better use Net::Ping it can ping to all your hosts at once and wait for some defined time then it reports back who responds.
And the best, it works without (i)threads at all.
Boris
  • Comment on Re: Multi-threading ping of a list of hosts.....Again!

Replies are listed 'Best First'.
Re^2: Multi-threading ping of a list of hosts.....Again!
by BrowserUk (Patriarch) on Sep 20, 2004 at 18:12 UTC
    ... it can ping to all your hosts at once ...

    It can? How?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
      This example scan 253 hosts on my home wlan in 5 seconds. Change the TIMEOUT and or the ips array as you like.
      use Net::Ping; # fill this array with your ips my @ips = map { "192.168.1." . $_ } ( 2 .. 254 ); my @ips_up; use constant { TIMEOUT => 5000, PORT => 7 }; my $p = Net::Ping->new( "syn", TIMEOUT() / 1000 ); $p->{port_num} = PORT; $p->ping($_) for (@ips); while ( my ( $host, $rtt, $ip ) = $p->ack ) { push @ips_up, $ip; } local $" = "\n"; print @ips_up;
      Boris

        Neat, thanks.

        I've read scanned the Net::Ping docs a few times, but I've never picked up on the 'syn' stuff. Nor did I recall seeing this simple solution mentioned here before. Hence my question.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
        Hmmmmmm, Natha Senior, still didn't work, didn't even get any output or errors just back to my C prompt.

        Have I scripted something incorrect?

        Thanks

        These are the changes I made;
        use Net::Ping; my @ips; while (<DATA>) { chomp; push (@ips, $_); print "$_\n"; } # fill this array with your ips #my @ips = map { "192.168.1." . $_ } ( 2 .. 254 ); my @ips_up; use constant { TIMEOUT => 500, PORT => 7 }; my $p = Net::Ping->new( "syn", TIMEOUT() / 1000 ); $p->{port_num} = PORT; $p->ping($_) for (@ips); while ( my ( $host, $rtt, $ip ) = $p->ack ) { push @ips_up, $ip; } local $" = "\n"; print @ips_up; __DATA__ 172.24.175.53 172.24.166.15 172.24.184.43 172.24.175.10 172.24.184.46 172.24.175.55 172.24.184.12
        The output
        C:\Perl>ping_sweep3.pl C:\Perl>
        Blackadder