From b6734320585902d272b74121f27c6157324f5d56 Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 12 Aug 2016 21:39:53 +0100 Subject: [PATCH] Added support for nets-exclude in snmp-scan --- poller.php | 2 +- snmp-scan.php | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/poller.php b/poller.php index 36ee777a04..78254d8192 100755 --- a/poller.php +++ b/poller.php @@ -84,7 +84,7 @@ if (!$where) { echo "-r Do not create or update RRDs\n"; echo "-f Do not insert data into InfluxDB\n"; echo "-d Enable debugging output\n"; - echo "-d Enable verbose debugging output\n"; + echo "-v Enable verbose debugging output\n"; echo "-m Specify module(s) to be run\n"; echo "\n"; echo "No polling type specified!\n"; diff --git a/snmp-scan.php b/snmp-scan.php index fb864f9492..887ae06389 100755 --- a/snmp-scan.php +++ b/snmp-scan.php @@ -42,7 +42,7 @@ require 'includes/functions.php'; require 'includes/discovery/functions.inc.php'; function perform_snmp_scan($net) { - global $stats, $config, $debug; + global $stats, $config, $debug, $vdebug; echo 'Range: '.$net->network.'/'.$net->bitmask.PHP_EOL; $config['snmp']['timeout'] = 1; $config['snmp']['retries'] = 0; @@ -52,6 +52,10 @@ function perform_snmp_scan($net) { while ($start++ < $end) { $stats['count']++; $host = long2ip($start); + if (match_network($config['autodiscovery']['nets-exclude'], $host)) { + echo '|'; + continue; + } $test = isPingable($host); if ($test['result'] === false) { echo '.'; @@ -93,7 +97,7 @@ function perform_snmp_scan($net) { echo PHP_EOL; } -$opts = getopt('r:d::l::h::'); +$opts = getopt('r:d::v::l::h::'); $stats = array('count'=> 0, 'known'=>0, 'added'=>0, 'failed'=>0); $start = false; $debug = false; @@ -106,15 +110,19 @@ if (isset($opts['h']) || (empty($opts) && (!isset($config['nets']) || empty($con echo ' This argument is only requied if $config[\'nets\'] is not set'.PHP_EOL; echo ' Example: 192.168.0.0/24'.PHP_EOL; echo ' -d Enable Debug'.PHP_EOL; + echo ' -v Enable verbose Debug'.PHP_EOL; echo ' -l Show Legend'.PHP_EOL; echo ' -h Print this text'.PHP_EOL; exit(0); } -if (isset($opts['d'])) { +if (isset($opts['d']) || isset($opts['v'])) { + if (isset($opts['v'])) { + $vdebug = true; + } $debug = true; } if (isset($opts['l'])) { - echo ' * = Known Device; . = Unpingable Device; + = Added Device; - = Failed To Add Device;'.PHP_EOL; + echo ' * = Known Device; . = Unpingable Device; + = Added Device; - = Failed To Add Device; | = Excluded by config.php'.PHP_EOL; } if (isset($opts['r'])) { $net = Net_IPv4::parseAddress($opts['r']);