From 16121b372ca45c06d777a157228ddd6e8d14ad70 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 31 Mar 2009 21:21:36 +0000 Subject: [PATCH] Add a round trip time estimate to host status lines. It looks like Host scanme.nmap.org (64.13.134.52) is up (0.071s latency). --- CHANGELOG | 7 ++++--- output.cc | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1d34e24f4..093ab9cd3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,10 +3,11 @@ o Host status messages (up/down) are now uniform between ping scanning and port scanning. They used to vary slighly, but now they all look like - Host is up. + Host is up (Xs latency). Host is down. - In addition, the reason for a host being up is now printed for port - scans just as for ping scans, with the --reason option. [David] + The latency is Nmap's estimate of the round trip time. In addition, the + reason for a host being up is now printed for port scans just as for + ping scans, with the --reason option. [David] o [Zenmap] A typo that led to a crash if the ndiff subprocess terminated with an error was fixed. [David] The message was diff --git a/output.cc b/output.cc index 0aeff0e26..6b66cb602 100644 --- a/output.cc +++ b/output.cc @@ -1320,6 +1320,27 @@ static void write_xml_initial_hostinfo(Target *currenths, log_flush_all(); } +/* Convert a number to a string, keeping the given number of significant digits. + The result is returned in a static buffer. */ +static char *num_to_string_sigdigits(double d, unsigned int digits) { + static char buf[32]; + int shift; + int n; + + if (d == 0.0) { + shift = -digits; + } else { + shift = floor(log10(fabs(d))) - digits + 1; + d = floor(d / pow(10, shift) + 0.5); + d = d * pow(10, shift); + } + + n = Snprintf(buf, sizeof(buf), "%.*f", MAX(0, -shift), d); + assert(n > 0 && n < (int) sizeof(buf)); + + return buf; +} + /* Writes host status info to the log streams (including STDOUT). An example is "Host: 10.11.12.13 (foo.bar.example.com)\tStatus: Up\n" to machine log. resolve_all should be passed nonzero if the user asked @@ -1364,7 +1385,10 @@ void write_host_status(Target *currenths, int resolve_all) { log_write(LOG_PLAIN, "Host %s is up", currenths->NameIP(hostname, sizeof(hostname))); if (o.reason) log_write(LOG_PLAIN, ", %s", target_reason_str(currenths)); + if (currenths->to.srtt != -1) + log_write(LOG_PLAIN, " (%ss latency)", num_to_string_sigdigits(currenths->to.srtt / 1000000.0, 2)); log_write(LOG_PLAIN, ".\n"); + log_write(LOG_MACHINE,"Host: %s (%s)\tStatus: Up\n", currenths->targetipstr(), currenths->HostName()); } else if (o.verbose || resolve_all) { log_write(resolve_all ? LOG_PLAIN : LOG_STDOUT,