From 93f270155fd371a1e3884e7128fea1608b4b378f Mon Sep 17 00:00:00 2001 From: SourceDoctor Date: Fri, 7 Apr 2023 20:24:18 +0200 Subject: [PATCH] snmp-scan filter for dns resolved devices (#14934) * snmp-scan filter for dns resolved devices * . * add console arguments --- routes/console.php | 5 +++++ snmp-scan.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/routes/console.php b/routes/console.php index 228c738f70..eb05849dae 100644 --- a/routes/console.php +++ b/routes/console.php @@ -177,6 +177,7 @@ Artisan::command('poller:billing-calculate Artisan::command('scan {network?* : ' . __('CIDR notation network(s) to scan, can be ommited if \'nets\' config is set') . '} {--P|ping-only : ' . __('Add the device as a ping only device if it replies to ping but not SNMP') . '} + {--o|dns-only : ' . __('Only DNS resolved Devices') . '} {--t|threads=32 : ' . __('How many IPs to scan at a time, more will increase the scan speed, but could overload your system') . '} {--l|legend : ' . __('Print the legend') . '} ', function () { @@ -189,6 +190,10 @@ Artisan::command('scan return 1; } + if ($this->option('dns-only')) { + $command[] = '-o'; + } + if ($this->option('ping-only')) { $command[] = '-P'; } diff --git a/snmp-scan.py b/snmp-scan.py index 03163b2548..0a1cc15e65 100755 --- a/snmp-scan.py +++ b/snmp-scan.py @@ -43,6 +43,7 @@ class Outcome: FAILED = 4 EXCLUDED = 5 TERMINATED = 6 + NODNS = 7 POLLER_GROUP = "0" @@ -59,6 +60,7 @@ stats = { Outcome.FAILED: 0, Outcome.EXCLUDED: 0, Outcome.TERMINATED: 0, + Outcome.NODNS: 0, } @@ -75,6 +77,7 @@ def get_outcome_symbol(outcome): Outcome.KNOWN: "*", Outcome.FAILED: "-", Outcome.TERMINATED: "", + Outcome.NODNS: "", }[outcome] @@ -126,6 +129,9 @@ def scan_host(scan_ip): try: + if args.dns and not hostname: + return Result(scan_ip, hostname, Outcome.NODNS, "DNS not Resolved") + arguments = [ "/usr/bin/env", "lnms", @@ -134,9 +140,11 @@ def scan_host(scan_ip): POLLER_GROUP, hostname or scan_ip, ] + if args.ping: arguments.insert(5, args.ping) add_output = check_output(arguments) + return Result(scan_ip, hostname, Outcome.ADDED, add_output) except CalledProcessError as err: output = err.output.decode().rstrip() @@ -188,6 +196,15 @@ Example: 192.168.0.1/32 will be treated as a single host address""", POLLER_GROUP ), ) + + parser.add_argument( + "-o", + "--dns-only", + dest="dns", + action="store_true", + help="Only DNS resolved Devices", + ) + parser.add_argument("-l", "--legend", action="store_true", help="Print the legend.") parser.add_argument( "-v",