Skip to content

Commit 85fae8d

Browse files
authored
Merge pull request #811 from rafa-br34/master
feat: add option (--output-flush) to flush output buffer after every line
2 parents 0bc8534 + c03e8e7 commit 85fae8d

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎src/main-conf.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ print_nmap_help(void)
218218
" -oL/-oJ/-oD/-oG/-oB/-oX/-oU <file>: Output scan in List/JSON/nDjson/Grepable/Binary/XML/Unicornscan format,\n"
219219
" respectively, to the given filename. Shortcut for\n"
220220
" --output-format <format> --output-file <file>\n"
221+
" --output-flush: Flushes output per host found (recommended for real-time reading).\n"
221222
" -v: Increase verbosity level (use -vv or more for greater effect)\n"
222223
" -d: Increase debugging level (use -dd or more for greater effect)\n"
223224
" --open: Only show open (or possibly open) ports\n"
@@ -1627,6 +1628,18 @@ static int SET_output_append(struct Masscan *masscan, const char *name, const ch
16271628
return CONF_OK;
16281629
}
16291630

1631+
static int SET_output_flush(struct Masscan *masscan, const char *name, const char *value)
1632+
{
1633+
UNUSEDPARM(name);
1634+
if (masscan->echo) {
1635+
if (masscan->output.is_output_flush || masscan->echo_all)
1636+
fprintf(masscan->echo, "output-flush = %s\n", masscan->output.is_output_flush?"true":"false");
1637+
return 0;
1638+
}
1639+
masscan->output.is_output_flush = parseBoolean(value);
1640+
return CONF_OK;
1641+
}
1642+
16301643
static int SET_output_filename(struct Masscan *masscan, const char *name, const char *value)
16311644
{
16321645
UNUSEDPARM(name);
@@ -2395,6 +2408,7 @@ struct ConfigParameter config_parameters[] = {
23952408
{"output-noshow", SET_output_noshow, 0, {"noshow",0}},
23962409
{"output-show-open",SET_output_show_open, F_BOOL, {"open", "open-only", 0}},
23972410
{"output-append", SET_output_append, 0, {"append-output",0}},
2411+
{"output-flush", SET_output_flush, F_BOOL, {"output-flush",0}},
23982412
{"rotate", SET_rotate_time, 0, {"output-rotate", "rotate-output", "rotate-time", 0}},
23992413
{"rotate-dir", SET_rotate_directory, 0, {"output-rotate-dir", "rotate-directory", 0}},
24002414
{"rotate-offset", SET_rotate_offset, 0, {"output-rotate-offset", 0}},

‎src/masscan.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ struct Masscan
281281
* <stdout> rather than to a file.
282282
*/
283283
char filename[256];
284-
284+
285285
/**
286286
* A feature of the XML output where we can insert an optional
287287
* stylesheet into the file for better rendering on web browsers
@@ -344,6 +344,12 @@ struct Masscan
344344
*/
345345
unsigned is_status_updates:1;
346346

347+
/**
348+
* --output-flush
349+
* Flush the file with every host/banner found
350+
*/
351+
unsigned is_output_flush:1;
352+
347353
struct {
348354
/**
349355
* When we should rotate output into the target directory

‎src/output.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ output_create(const struct Masscan *masscan, unsigned thread_index)
415415
out->is_show_closed = masscan->output.is_show_closed;
416416
out->is_show_host = masscan->output.is_show_host;
417417
out->is_append = masscan->output.is_append;
418+
out->is_output_flush = masscan->output.is_output_flush;
418419
out->xml.stylesheet = duplicate_string(masscan->output.stylesheet);
419420
out->rotate.directory = duplicate_string(masscan->output.rotate.directory);
420421
if (masscan->nic_count <= 1)
@@ -873,6 +874,9 @@ output_report_status(struct Output *out, time_t timestamp, int status,
873874
* and so on.
874875
*/
875876
out->funcs->status(out, fp, timestamp, status, ip, ip_proto, port, reason, ttl);
877+
878+
if (out->is_output_flush)
879+
fflush(fp);
876880
}
877881

878882

@@ -947,6 +951,8 @@ output_report_banner(struct Output *out, time_t now,
947951
*/
948952
out->funcs->banner(out, fp, now, ip, ip_proto, port, proto, ttl, px, length);
949953

954+
if (out->is_output_flush)
955+
fflush(fp);
950956
}
951957

952958

‎src/output.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct Output
8383

8484
unsigned is_banner:1; /* --banners */
8585
unsigned is_banner_rawudp:1; /* --rawudp */
86+
unsigned is_output_flush:1; /* --output-flush */
8687
unsigned is_gmt:1; /* --gmt */
8788
unsigned is_interactive:1; /* echo to command line */
8889
unsigned is_show_open:1; /* show open ports (default) */

0 commit comments

Comments
 (0)