From bad0e61739bb8d2c6a73f3eb7c54d28cabc6a14a Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 17 Dec 2020 17:34:32 +0000 Subject: [PATCH] Fix grepable output when all scanned ports are ignored Previous behavior was to output an extra host status line "Status: up" New behavior outputs an empty "Ports: \t" then the "Ignored State" field. --- output.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/output.cc b/output.cc index f9f8e4d36..d89c70e9d 100644 --- a/output.cc +++ b/output.cc @@ -553,8 +553,16 @@ void printportoutput(Target *currenths, PortList *plist) { log_write(LOG_PLAIN, "All %d scanned ports on %s are ", numignoredports, currenths->NameIP(hostname, sizeof(hostname))); + log_write(LOG_MACHINE, "Host: %s (%s)\t%s: ", + currenths->targetipstr(), currenths->HostName(), + (o.ipprotscan) ? "Protocols" : "Ports"); + if (plist->numIgnoredStates() == 1) { - log_write(LOG_PLAIN, "%s", statenum2str(plist->nextIgnoredState(PORT_UNKNOWN))); + istate = plist->nextIgnoredState(PORT_UNKNOWN); + log_write(LOG_PLAIN, "%s", statenum2str(istate)); + /* Grepable output supports only one ignored state. */ + log_write(LOG_MACHINE, "\tIgnored State: %s (%d)", + statenum2str(istate), plist->getStateCounts(istate)); } else { prevstate = PORT_UNKNOWN; while ((istate = plist->nextIgnoredState(prevstate)) != PORT_UNKNOWN) { @@ -570,8 +578,6 @@ void printportoutput(Target *currenths, PortList *plist) { log_write(LOG_PLAIN, "\n"); } - log_write(LOG_MACHINE, "Host: %s (%s)\tStatus: Up", - currenths->targetipstr(), currenths->HostName()); xml_end_tag(); /* ports */ xml_newline(); return;