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).
This commit is contained in:
david 2009-03-31 21:21:36 +00:00
parent 74ffd7b4c7
commit 16121b372c
2 changed files with 28 additions and 3 deletions

View file

@ -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 <host> is up.
Host <host> is up (Xs latency).
Host <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

View file

@ -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,