in reply to Re^2: Multi-threading ping of a list of hosts.....Again!
in thread Multi-threading ping of a list of hosts.....Again!

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

Replies are listed 'Best First'.
Re^4: Multi-threading ping of a list of hosts.....Again!
by BrowserUk (Patriarch) on Sep 20, 2004 at 22:46 UTC

    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
Re^4: Multi-threading ping of a list of hosts.....Again!
by blackadder (Hermit) on Sep 23, 2004 at 11:36 UTC
    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
      Perhaps your timeout is a little to low?
      Try 2000. My example is tested and work at least on linux and OSX.
      Boris