1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-07 06:59:03 +00:00

Simplify and combine the write_host_status code for ping scan and port

scans. This is the code that prints
	Host ... appears to be up.
	Host ... appears to be down.
	Host ... appears to be up ... good.
	Host ... appears to be down, skipping it
Except that now these messages are uniform and are
	Host ... is up.
	Host ... is down.
In addition, the host state --reason information is printed for port
scans just as for ping scans, which appears to have been an oversight
before.
This commit is contained in:
david
2009-03-31 19:57:25 +00:00
parent fbb73481d3
commit d1a77bb85e
3 changed files with 20 additions and 34 deletions

View File

@@ -1,5 +1,13 @@
# Nmap Changelog ($Id$); -*-text-*-
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 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]
o [Zenmap] A typo that led to a crash if the ndiff subprocess
terminated with an error was fixed. [David] The message was
File "zenmapGUI\DiffCompare.pyo", line 331, in check_ndiff_process

View File

@@ -1326,7 +1326,6 @@ static void write_xml_initial_hostinfo(Target *currenths,
for all hosts (even down ones) to be resolved */
void write_host_status(Target *currenths, int resolve_all) {
char hostname[1200];
char reasonbuf[512];
if (o.listscan) {
/* write "unknown" to stdout, machine, and xml */
@@ -1356,42 +1355,21 @@ void write_host_status(Target *currenths, int resolve_all) {
}
}
else if (o.pingscan) {
else { /* Ping scan / port scan. */
if(o.reason && currenths->flags & HOST_UP)
Snprintf(reasonbuf, 512, "%s.\n", target_reason_str(currenths));
else
Snprintf(reasonbuf, 512, ".\n");
write_xml_initial_hostinfo(currenths,
(currenths->flags & HOST_UP)? "up" : "down");
if (currenths->flags & HOST_UP) {
log_write(LOG_PLAIN,"Host %s appears to be up%s", currenths->NameIP(hostname, sizeof(hostname)), reasonbuf);
log_write(LOG_MACHINE,"Host: %s (%s)\tStatus: Up\n", currenths->targetipstr(), currenths->HostName());
} else if (o.verbose || resolve_all) {
if (resolve_all)
log_write(LOG_PLAIN,"Host %s appears to be down.\n", currenths->NameIP(hostname, sizeof(hostname)));
else log_write(LOG_STDOUT,"Host %s appears to be down.\n", currenths->NameIP(hostname, sizeof(hostname)));
log_write(LOG_MACHINE, "Host: %s (%s)\tStatus: Down\n", currenths->targetipstr(), currenths->HostName());
}
}
else { /* Normal case (non ping/list scan or smurf address) */
write_xml_initial_hostinfo(currenths,
(currenths->flags & HOST_UP)? "up" : "down");
if (o.verbose) {
if (o.pingscan || o.verbose) {
if (currenths->flags & HOST_UP) {
log_write(LOG_STDOUT, "Host %s appears to be up ... good.\n",
currenths->NameIP(hostname, sizeof(hostname)));
} else {
if (resolve_all) {
log_write(LOG_PLAIN,"Host %s appears to be down, skipping it.\n", currenths->NameIP(hostname, sizeof(hostname)));
}
else {
log_write(LOG_STDOUT,"Host %s appears to be down, skipping it.\n", currenths->NameIP(hostname, sizeof(hostname)));
}
log_write(LOG_MACHINE, "Host: %s (%s)\tStatus: Down\n", currenths->targetipstr(), currenths->HostName());
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));
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,
"Host %s is down.\n", currenths->NameIP(hostname, sizeof(hostname)));
log_write(LOG_MACHINE, "Host: %s (%s)\tStatus: Down\n", currenths->targetipstr(), currenths->HostName());
}
}
}

View File

@@ -356,7 +356,7 @@ char *target_reason_str(Target *t) {
static char reason[128];
memset(reason,'\0', 128);
assert(t->reason.reason_id != ER_NORESPONSE);
Snprintf(reason, 128, ", received %s",reason_str(t->reason.reason_id, SINGULAR));
Snprintf(reason, 128, "received %s", reason_str(t->reason.reason_id, SINGULAR));
return reason;
}