rookie8278 has asked for the wisdom of the Perl Monks concerning the following question:

I have written a tool to scan all alive machines in a windows subnet. The current design is start a scan on a IP-->complete the scan of the IP and then take up the next IP. Scanning is initiated from a single host machine and all the other machines are scanned remotely one by one. This has been taking a lot of time to complete the scan of all 253 machine in the subnet. My thoughts were to go for multithreading to reduce the time taken for the scan? Any thoughts or suggestions here? -Kishore
  • Comment on multithreading solution to the below problem

Replies are listed 'Best First'.
Re: multithreading solution to the below problem
by BrowserUk (Patriarch) on Jun 25, 2009 at 07:15 UTC

    Consider using Net::Ping with the 'syn' protocol (and ->ack()</c> method) to overlap your pings. It's far more efficient than a multithreaded solution, and easier to write.


    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.
      hey there..thanks for ur reply...pardon me for my lack of knowledge on perl, i did not completely get ur answer :-O let me rephrase, if there are IP1,IP2,...IP255 alive machines in a subnet, the current way of doing is, wait for scan of IP1 to complete and then start scan of IP2 and so on,This takes a lot of time to complete the scan, i am looking into ways where i can send a scan request to more than one machine simultaneously, Does your answer cover this..can u please elaborate.

        Have you read Net::Ping? It describes how you can ping multiple hosts without even needing threads. Please just read Net::Ping and ask specific questions after you've done so. The relevant example from the Net::Ping documentation is:

        # Like tcp protocol, but with many hosts $p = Net::Ping->new("syn"); $p->port_number(getservbyname("http", "tcp")); foreach $host (@host_array) { $p->ping($host); } while (($host,$rtt,$ip) = $p->ack) { print "HOST: $host [$ip] ACKed in $rtt seconds.\n"; }
Re: multithreading solution to the below problem
by imrags (Monk) on Jun 26, 2009 at 05:41 UTC
    Well, i'd written a similar utility to scan around 10,000 devices for ping,
    I used Threads with semaphore. Since it's windows, be careful about concurrent threads.
    The whole operation took around 20 mins. But i had a limitation of memory consumption
    as well. Here are the modules i used:
    use threads qw(yield); use Thread::Semaphore; use Net::Ping; use Socket;
    Raghu
      Thanks Raghu
Re: multithreading solution to the below problem
by hpavc (Acolyte) on Jun 26, 2009 at 09:41 UTC

    As its unlikely that you just want to ping the subnet.

    I would use nmap for this in a pipe from perl. With the -oX argument for XML output or similar output format to read in.