in reply to Does Net::Ping have concurrency issues?

Suggestions:

  • Comment on Re: Does Net::Ping have concurrency issues?

Replies are listed 'Best First'.
Re: Re: Does Net::Ping have concurrency issues?
by phydeauxarff (Priest) on May 30, 2003 at 21:19 UTC
    We had a similar issue where we needed to run through about 40 thousand IP addresses to make sure folks weren't using IP's not assigned to them....Using Parallel::ForkManager made this much simpler.

    For more detail on the method I used to setup the mySQL connection check out Re: Re: Re: Secure ways to use DBI?

    The code below pulls the IP's from a database and runs through them 50 at a time...it runs quite well on a Ultra-Sparc 60

    #!/usr/bin/perl use Net::Ping; use DBI (); use Data_config; use Parallel::ForkManager; my $MAX_PROCESSES = 50; ## Create a database handle ## ## The actual user/pass info is in Data_config.pl ## my $DSN = "DBI:$DBDRIVER:database=$DATABASE:host=$DBHOST:port=$DBPORT" +; my $DBH = DBI->connect($DSN, $USERNAME, $PASSWORD, { RaiseError => 1, PrintError => 1 }); $|=1; my $PING_TIMEOUT = 2; $pm = new Parallel::ForkManager($MAX_PROCESSES); foreach my $IP (map { $_->[0] } @{ $DBH->selectall_arrayref( "SELECT ip_address FROM ips" )}) { # Forks and returns the pid for the child: my $pid = $pm->start and next; my $ping = new Net::Ping ("icmp"); if ($ping->ping($IP, $PING_TIMEOUT)) { print "$IP Gotcha! \n"; } else { print "$IP \n"; } $ping->close(); $pm->finish; # Terminates the child process } $pm->wait_all_children;