Instead of using four nested for loops you could do it like this:
#!/usr/bin/perl use warnings; use strict; use Net::SNMP qw(snmp_dispatcher oid_lex_sort); #use Smart::Comments '###'; use Socket; my $startip = $ARGV[ 0 ] or die 'Missing Starting IP'; my $endip = $ARGV[ 1 ] or die 'Missing Ending IP'; my $community = $ARGV[ 2 ] or die 'Missing community string'; my $ip_start = unpack 'N', inet_aton $startip; my $ip_end = unpack 'N', inet_aton $endip; my $contadr = 0; for my $i ( $ip_start .. $ip_end ) { my $ip = inet_ntoa pack 'N', $i my ( $session, $error ) = Net::SNMP->session( -hostname => $ip, -version => 'snmpv2c', -nonblocking => 1, -community => $community, -timeout => 3, -retries => 1, ); if ( defined $session ) { my $serialno = '.1.3.6.1.3.83.1.1.4.0'; my $mac = '.1.3.6.1.2.1.2.2.1.6.2'; my @msoids = ( $hfcmac, $serialno ); my $result = $session->get_request( -varbindlist => \@msoids, callback => [ \&getms, $session, $ip ] ); $session->close; ## reason for all this close, is that they dont seem to get #closed no + matter where i put them } else { print "Session not defined! $error\n"; } $session->close; snmp_dispatcher(); } exit;
In reply to Re: How to improve memory usage in this script??
by jwkrahn
in thread How to improve memory usage in this script??
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |