#! perl use strict; use threads; use threads::shared; use Net::SNMP; sub polldevice { my( $running, $stop, $host, $community, $delay ) = @_; ++$running; my( $session, $error ) = Net::SNMP->session( Hostname => $host, Community => $community ) or die "session error:" . $session->error; do { my $result = $session->get_request( "1.3.6.1.2.1.1.2.0", "1.3.6.1.2.1.2.1.0", "1.3.6.1.2.1.1.3.0" ) or die "request error: " . $session->error; print "Testing ".$host."\n"; print "Number of interfaces: ".$result->{"1.3.6.1.2.1.2.1.0"}."\n"; print "uptime: " . $result->{"1.3.6.1.2.1.1.3.0"}."\n"; print "sysOID: " . $result->{"1.3.6.1.2.1.1.2.0"}."\n"; } while not $stop and sleep $delay; $session->close; --$running; } my $stop :shared = 0; my $running :shared = 0; while( ) { async{ \&polldevice, $stop, split ' ' }->detach; } $SIG{INT} = sub{ $stop = 1 }; sleep 1 until $stop; sleep 1 while $running; __DATA__ 192.168.1.50 public 10 192.168.1.1 public 25 192.168.1.2 public 60 192.168.1.3 public 45 192.168.1.4 public 12 192.168.1.5 public 59 192.168.1.6 public 01