From 7d0fbfb4c27cba28dc7687268dcc5b14956636f1 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 12 Mar 2010 22:15:22 +0000 Subject: [PATCH] Don't print output for hosts that don't have any open ports when --open is used. See discussion at http://seclists.org/nmap-dev/2010/q1/837. In this patch, all output formats are treated the same. So if a host isn't shown in normal output, it's not shown in XML output either. --- nmap.cc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/nmap.cc b/nmap.cc index f76d2599d..2e801a5b9 100644 --- a/nmap.cc +++ b/nmap.cc @@ -1766,7 +1766,7 @@ int nmap_main(int argc, char *argv[]) { /* I used to check that !currenths->weird_responses, but in some rare cases, such IPs CAN be port successfully scanned and even connected to */ if (!(currenths->flags & HOST_UP)) { - if (o.verbose) { + if (o.verbose && (!o.openOnly() || currenths->ports.hasOpenPorts())) { log_write(LOG_XML, ""); write_host_header(currenths); log_write(LOG_XML, "\n"); @@ -1914,16 +1914,21 @@ int nmap_main(int argc, char *argv[]) { for(targetno = 0; targetno < Targets.size(); targetno++) { currenths = Targets[targetno]; /* Now I can do the output and such for each host */ - log_write(LOG_XML, "", - (unsigned long) currenths->StartTime(), - (unsigned long) currenths->EndTime()); - write_host_header(currenths); if (currenths->timedOut(NULL)) { + write_host_header(currenths); log_write(LOG_PLAIN,"Skipping host %s due to host timeout\n", currenths->NameIP(hostname, sizeof(hostname))); log_write(LOG_MACHINE,"Host: %s (%s)\tStatus: Timeout", currenths->targetipstr(), currenths->HostName()); } else { + /* --open means don't show any hosts without open ports. */ + if (o.openOnly() && !currenths->ports.hasOpenPorts()) + continue; + + log_write(LOG_XML, "", + (unsigned long) currenths->StartTime(), + (unsigned long) currenths->EndTime()); + write_host_header(currenths); printportoutput(currenths, ¤ths->ports); printmacinfo(currenths); printosscanoutput(currenths); @@ -1931,15 +1936,12 @@ int nmap_main(int argc, char *argv[]) { #ifndef NOLUA printhostscriptresults(currenths); #endif + if (o.traceroute) + printtraceroute(currenths); + printtimes(currenths); + log_write(LOG_PLAIN|LOG_MACHINE,"\n"); + log_write(LOG_XML, "\n"); } - - if (o.traceroute) - printtraceroute(currenths); - - printtimes(currenths); - - log_write(LOG_PLAIN|LOG_MACHINE,"\n"); - log_write(LOG_XML, "\n"); } log_flush_all();