From ecb9aa0565d32d22ea81a479d8a2efc54ede10ef Mon Sep 17 00:00:00 2001 From: david Date: Mon, 16 Nov 2009 07:37:01 +0000 Subject: [PATCH] Print output for down hosts, even when doing scanning past a ping scan. This always goes to XML and grepable output. It goes to normal in interactive output in verbose mode. The format for printing a down host is changed slightly: Nmap scan report for 1.1.1.1 [host down] --- nmap.cc | 3 +++ output.cc | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nmap.cc b/nmap.cc index 65059f836..e8f5953fc 100644 --- a/nmap.cc +++ b/nmap.cc @@ -1747,6 +1747,9 @@ 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)) { + log_write(LOG_XML, ""); + write_host_header(currenths); + log_write(LOG_XML, "\n"); delete currenths; o.numhosts_scanned++; continue; diff --git a/output.cc b/output.cc index d148d8a98..3550eaf6b 100644 --- a/output.cc +++ b/output.cc @@ -1424,8 +1424,12 @@ static char *num_to_string_sigdigits(double d, int digits) { /* Writes a heading for a full scan report ("Nmap scan report for..."), including host status and DNS records. */ void write_host_header(Target *currenths) { - if ((currenths->flags & HOST_UP) || o.verbose || o.resolve_all) - log_write(LOG_PLAIN, "Nmap scan report for %s\n", currenths->NameIP()); + if ((currenths->flags & HOST_UP) || o.verbose || o.resolve_all) { + if (currenths->flags & HOST_UP) + log_write(LOG_PLAIN, "Nmap scan report for %s\n", currenths->NameIP()); + else if (currenths->flags & HOST_DOWN) + log_write(LOG_PLAIN, "Nmap scan report for %s [host down]\n", currenths->NameIP()); + } write_host_status(currenths, o.resolve_all); if (currenths->TargetName() != NULL && currenths->resolved_addrs.size() > 1) { @@ -1488,8 +1492,7 @@ void write_host_status(Target * currenths, int resolve_all) { log_write(LOG_MACHINE, "Host: %s (%s)\tStatus: Up\n", currenths->targetipstr(), currenths->HostName()); - } else if (o.verbose || resolve_all) { - log_write(LOG_PLAIN, "Host is down.\n"); + } else if (currenths->flags & HOST_DOWN) { log_write(LOG_MACHINE, "Host: %s (%s)\tStatus: Down\n", currenths->targetipstr(), currenths->HostName()); }