snmpscan.py output errors and nodns (#15673)

* snmpscan.py output errors and nodns
Add symbols for nodns (-o) and errors.
-v will include detailed info as always.

* Add E to legend

* fix too long lines

* Fix it the way black wants, apparently.

* try 3

* attempt 4
This commit is contained in:
Tony Murray
2024-05-08 09:51:44 -05:00
committed by GitHub
parent 0ac1414905
commit 4b3e6ebf15

View File

@@ -44,6 +44,7 @@ class Outcome:
EXCLUDED = 5 EXCLUDED = 5
TERMINATED = 6 TERMINATED = 6
NODNS = 7 NODNS = 7
ERROR = 8
POLLER_GROUP = "0" POLLER_GROUP = "0"
@@ -61,6 +62,7 @@ stats = {
Outcome.EXCLUDED: 0, Outcome.EXCLUDED: 0,
Outcome.TERMINATED: 0, Outcome.TERMINATED: 0,
Outcome.NODNS: 0, Outcome.NODNS: 0,
Outcome.ERROR: 0,
} }
@@ -77,7 +79,8 @@ def get_outcome_symbol(outcome):
Outcome.KNOWN: "*", Outcome.KNOWN: "*",
Outcome.FAILED: "-", Outcome.FAILED: "-",
Outcome.TERMINATED: "", Outcome.TERMINATED: "",
Outcome.NODNS: "", Outcome.NODNS: "~",
Outcome.ERROR: "E",
}[outcome] }[outcome]
@@ -128,7 +131,6 @@ def scan_host(scan_ip):
pass pass
try: try:
if args.dns and not hostname: if args.dns and not hostname:
return Result(scan_ip, hostname, Outcome.NODNS, "DNS not Resolved") return Result(scan_ip, hostname, Outcome.NODNS, "DNS not Resolved")
@@ -155,6 +157,8 @@ def scan_host(scan_ip):
return Result(scan_ip, hostname, Outcome.FAILED, output) return Result(scan_ip, hostname, Outcome.FAILED, output)
elif err.returncode == 3: elif err.returncode == 3:
return Result(scan_ip, hostname, Outcome.KNOWN, output) return Result(scan_ip, hostname, Outcome.KNOWN, output)
elif err.returncode == 1:
return Result(scan_ip, hostname, Outcome.ERROR, output)
except KeyboardInterrupt: except KeyboardInterrupt:
return Result(scan_ip, hostname, Outcome.TERMINATED, "Terminated") return Result(scan_ip, hostname, Outcome.TERMINATED, "Terminated")
@@ -316,7 +320,7 @@ Example: 192.168.0.1/32 will be treated as a single host address""",
if args.legend and not VERBOSE_LEVEL: if args.legend and not VERBOSE_LEVEL:
print( print(
"Legend:\n+ Added device\n* Known device\n- Failed to add device\n. Ping failed\n" "Legend:\n+ Added device\n* Known device\n- Failed to add device\n. Ping failed\n~ Skipped due to no Reverse DNS\nE Error when checking\n"
) )
print("Scanning IPs:") print("Scanning IPs:")
@@ -353,5 +357,16 @@ Example: 192.168.0.1/32 will be treated as a single host address""",
) )
if stats[Outcome.EXCLUDED]: if stats[Outcome.EXCLUDED]:
summary += ", {} ips excluded by config".format(stats[Outcome.EXCLUDED]) summary += ", {} ips excluded by config".format(stats[Outcome.EXCLUDED])
if stats[Outcome.NODNS]:
summary += ", {} ips excluded due to missing reverse DNS record".format(
stats[Outcome.NODNS]
)
if stats[Outcome.ERROR]:
summary += (
", {} errors while checking device (try with -v to see errors)".format(
stats[Outcome.ERROR]
)
)
print(summary) print(summary)
print("Runtime: {:.2f} seconds".format(time() - start_time)) print("Runtime: {:.2f} seconds".format(time() - start_time))