Since your problem has specifically to do with SNMP polling, you probably ought to have a look at the callback function in the SNMP.pm module that comes with Net-SNMP (NOT the Net::SNMP module from CPAN). With it, you can set up several (more than 100) concurrent SNMP sessions at once. I use this to scan my network for new devices. Here's the code:
...
# Open the SNMP session and query in the background.
$sess = new SNMP::Session(DestHost => $thisip,
Community => $$optionsref{community},
Retries => $$optionsref{retries},
Timeout => $$optionsref{timeout},
Version => '1');
$mib = 'sysDescr';
$vb = new SNMP::Varbind([$mib]);
# The responses to our queries are stored in %list.
$var = $sess->getnext($vb, [ \&gotit, $thisip, \%list ]);
# Update the rate limiting counter.
$count++;
# After every 100 IP's, wait for the timeout period (default is two se
+conds) to keep from overwhelming routers with ARP queries.
if ( $count > '100' ) {
&SNMP::MainLoop($looptimer);
$count = 0;
}
# Increment the IP address for the next pass.
$intip++;
...
# This is the little function called by SNMP::MainLoop when a callback
+ comes in. It just stuffs the value of the response (if any) into th
+e appropriate place in %list and returns.
sub gotit {
my $myip = shift;
my $listref = shift;
my $vl = shift;
if ( defined $$vl[0] ) {
$$listref{$myip}{desc} = $$vl[0]->val;
}
return();
}
You then set your "connection" limit however you want. I used 100 as an arbitrary limit above. Since IP addresses are accepted by inet_aton($someint), you can just convert IPs to integers and increment them to step through a subnet or range of IP addresses. Here's the conversion:
($octet1, $octet2, $octet3, $octet4) = split /\./, $$argsref{ip};
$intip = ($octet1 * (256 ** 3)) + ($octet2 * (256 ** 2)) + ($octet3 *
+256) + $octet4;
Probably a little kludgy, but it works. There's probably a more elegant way to do it using inet_aton() and then converting directly from the 32-bit packed value to an int, but I haven't worked it out yet.
Anyway, hopefully the callback stuff above will help you out. See 'perldoc SNMP' for more info on that.
--Rhys