Skip to content

Commit 18c4c77

Browse files
Fix output printing when Silent option is enabled in SDK
Currently, when using the Naabu SDK with the Silent option enabled, the scan results are still printed to stdout due to unconditional logging. This change adds a conditional check around all stdout printing blocks to respect the Silent flag in runner options. With this fix, no output will be printed automatically when Silent is true, allowing users to fully control result output via the OnResult callback. This improves SDK usability by preventing unwanted console output, enabling cleaner integration into other tools and pipelines.
1 parent 22c2052 commit 18c4c77

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

pkg/runner/runner.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,19 @@ func (r *Runner) onReceive(hostResult *result.HostResult) {
243243
}
244244
}
245245
}
246-
if r.options.JSON {
247-
gologger.Silent().Msgf("%s", buffer.String())
248-
} else if r.options.CSV {
249-
writer.Flush()
250-
gologger.Silent().Msgf("%s", buffer.String())
251-
} else {
252-
for _, p := range hostResult.Ports {
253-
if r.options.OutputCDN && isCDNIP {
254-
gologger.Silent().Msgf("%s:%d [%s]\n", host, p.Port, cdnName)
255-
} else {
256-
gologger.Silent().Msgf("%s:%d\n", host, p.Port)
246+
if !r.options.Silent {
247+
if r.options.JSON {
248+
gologger.Silent().Msgf("%s", buffer.String())
249+
} else if r.options.CSV {
250+
writer.Flush()
251+
gologger.Silent().Msgf("%s", buffer.String())
252+
} else {
253+
for _, p := range hostResult.Ports {
254+
if r.options.OutputCDN && isCDNIP {
255+
gologger.Silent().Msgf("%s:%d [%s]\n", host, p.Port, cdnName)
256+
} else {
257+
gologger.Silent().Msgf("%s:%d\n", host, p.Port)
258+
}
257259
}
258260
}
259261
}
@@ -1071,16 +1073,18 @@ func (r *Runner) handleOutput(scanResults *result.Result) {
10711073
data.Host = host
10721074
}
10731075
}
1074-
if r.options.JSON {
1075-
gologger.Silent().Msgf("%s", buffer.String())
1076-
} else if r.options.CSV {
1077-
writer.Flush()
1078-
gologger.Silent().Msgf("%s", buffer.String())
1079-
} else {
1080-
if r.options.OutputCDN && isCDNIP {
1081-
gologger.Silent().Msgf("%s [%s]\n", host, cdnName)
1076+
if !r.options.Silent {
1077+
if r.options.JSON {
1078+
gologger.Silent().Msgf("%s", buffer.String())
1079+
} else if r.options.CSV {
1080+
writer.Flush()
1081+
gologger.Silent().Msgf("%s", buffer.String())
10821082
} else {
1083-
gologger.Silent().Msgf("%s\n", host)
1083+
if r.options.OutputCDN && isCDNIP {
1084+
gologger.Silent().Msgf("%s [%s]\n", host, cdnName)
1085+
} else {
1086+
gologger.Silent().Msgf("%s\n", host)
1087+
}
10841088
}
10851089
}
10861090
// file output

0 commit comments

Comments
 (0)