From fac82a011b0eda37b6b028ebc84e392d294ff318 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 4 May 2009 22:59:35 +0000 Subject: [PATCH] Only increment o.numhosts_scanned when we have truly finished scanning a host, which means that it is either found down or else all port/script/traceroute/etc. scanning is finished. In r12798 I made it be updated as soon as DNS resolution happened, to make the status display "X undergoing Ping Scan" accurate. However the main loop also uses this variable to count how many addresses have been generated so it knows when to stop scanning random addresses. If -iR was used, only the first hostgroup out of all the random addresses would be fully scanned and then the scan would end. This change fixes that and also makes the output more like it was pre-r12798; for example, if you had done name resolution on 1024 hosts with --max-hostgroup 8, and had found the 8th up host at the 280th one pinged, the output was Stats: 0:00:29 elapsed; 1016 hosts completed (8 up), 8 undergoing Connect Scan and is now Stats: 0:00:29 elapsed; 272 hosts completed (8 up), 8 undergoing Connect Scan --- nmap.cc | 7 +++++-- output.cc | 2 +- targets.cc | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nmap.cc b/nmap.cc index 09b79554b..15b124571 100644 --- a/nmap.cc +++ b/nmap.cc @@ -1607,7 +1607,7 @@ int nmap_main(int argc, char *argv[]) { num_host_exp_groups = 0; /* Now grab any new expressions */ while(num_host_exp_groups < o.ping_group_sz && - (!o.max_ips_to_scan || o.max_ips_to_scan > o.numhosts_scanned + num_host_exp_groups) && + (!o.max_ips_to_scan || o.max_ips_to_scan > o.numhosts_scanned + Targets.size() + num_host_exp_groups) && (host_spec = grab_next_host_spec(inputfd, argc, fakeargv))) { // For purposes of random scan host_exp_group[num_host_exp_groups++] = strdup(host_spec); @@ -1653,6 +1653,7 @@ int nmap_main(int argc, char *argv[]) { rare cases, such IPs CAN be port successfully scanned and even connected to */ if (!(currenths->flags & HOST_UP)) { delete currenths; + o.numhosts_scanned++; continue; } @@ -1685,7 +1686,7 @@ int nmap_main(int argc, char *argv[]) { if (Targets.size() > 0 && strcmp(Targets[Targets.size() - 1]->deviceName(), currenths->deviceName())) { returnhost(hstate); - o.numhosts_scanned--; o.numhosts_up--; + o.numhosts_up--; break; } o.decoys[o.decoyturn] = currenths->v4source(); @@ -1847,6 +1848,8 @@ int nmap_main(int argc, char *argv[]) { log_write(LOG_XML, "\n"); } log_flush_all(); + + o.numhosts_scanned += Targets.size(); /* Free all of the Targets */ while(!Targets.empty()) { diff --git a/output.cc b/output.cc index af1a92fd9..36c33341b 100644 --- a/output.cc +++ b/output.cc @@ -1896,7 +1896,7 @@ void printStatusMessage() { log_write(LOG_STDOUT, "Stats: %d:%02d:%02d elapsed; %d hosts completed (%d up), %d undergoing %s\n", - time/60/60, time/60 % 60, time % 60, o.numhosts_scanned - o.numhosts_scanning, + time/60/60, time/60 % 60, time % 60, o.numhosts_scanned, o.numhosts_up, o.numhosts_scanning, scantype2str(o.current_scantype)); } diff --git a/targets.cc b/targets.cc index f278f4741..d3f7d7b2a 100644 --- a/targets.cc +++ b/targets.cc @@ -529,7 +529,6 @@ do { goto batchfull; } hs->current_batch_sz++; - o.numhosts_scanned++; } if (hs->current_batch_sz < hs->max_batch_sz &&