Some minor cosmetic and functional tweaks to your great code:

* Combined the "while(1) with the next 2 lines
* Added a result q , and print of results
* Yield proc on successful ping
* Changed ping packet size so it doesnt get blocked by "Nachi" virus blockers
* Added a "real" range of 256 IP's to ping.

Here is the result:

use strict; use threads; use Thread::Queue; use Net::Ping; my $ThreadCount = 12; my @Threads; my $ServerQueue = Thread::Queue->new; my $ResultQ = Thread::Queue->new; my @Servers; push @Servers, qq(4.2.2.$_) for (1..254); foreach my $Item (@Servers) { $ServerQueue->enqueue($Item); } for (1..$ThreadCount) { my $Thread = threads->new(\&Process, $ServerQueue); push (@Threads, $Thread); } foreach my $Thread (@Threads) { $Thread->join(); } print "\n--results---\n"; while (my $target = $ResultQ->dequeue_nb){ print " $target\n"; } ##################################### sub Process { my $ServerQueue = shift; my $pingobj = Net::Ping->new("icmp",5,100); while (my $Server = $ServerQueue->dequeue_nb()) { if ($pingobj->ping($Server)) { #ping was good $ResultQ->enqueue ($Server); threads->yield(); } else { #ping was bad } } }

In reply to Re: Re: Non-blocking pings on Win32 by NetWallah
in thread Non-blocking pings on Win32 by TheFluffyOne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.