Skip to content

Commit b113043

Browse files
committed
#8: Add new skip output options (#32)
* #8: Add skip options to OutputOptions struct * #8: Add skip option flags for command line * #8: Add new output options to the README * #8: Add new output options to HTML template * #8: Add new output options to Markdown template
1 parent 76b2f95 commit b113043

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ nmap-formatter [path-to-nmap.xml] md > some-markdown.md
4949
* `--skip-down-hosts` skips hosts that are down
5050
* Applicable in: `html`, `md`, `csv`
5151
* Default: `true`
52+
* `--skip-summary` skips summary table
53+
* Applicable in: `html`, `md`
54+
* Default: `false`
55+
* `--skip-traceroute` skips traceroute information
56+
* Applicable in: `html`
57+
* Default: `false`
58+
* `--skip-metrics` skips metrics information
59+
* Applicable in: `html`
60+
* Default: `false`
61+
* `--skip-port-scripts` skips port scripts information in ports table
62+
* Applicable in: `html`, `md`
63+
* Default: `false`
5264
* `--json-pretty` pretty-prints JSON
5365
* Applicable in: `json`
5466
* Default: `true`

cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func init() {
6464

6565
// Some options related to the output
6666
rootCmd.Flags().BoolVar(&config.OutputOptions.SkipDownHosts, "skip-down-hosts", true, "--skip-down-hosts=false")
67+
rootCmd.Flags().BoolVar(&config.OutputOptions.SkipSummary, "skip-summary", false, "--skip-summary=true, skips summary in HTML/Markdown output")
68+
rootCmd.Flags().BoolVar(&config.OutputOptions.SkipTraceroute, "skip-traceroute", false, "--skip-traceroute=true, skips traceroute information in HTML/Markdown output")
69+
rootCmd.Flags().BoolVar(&config.OutputOptions.SkipMetrics, "skip-metrics", false, "--skip-metrics=true, skips metrics information in HTML/Markdown output")
70+
rootCmd.Flags().BoolVar(&config.OutputOptions.SkipPortScripts, "skip-port-scripts", false, "--skip-port-scripts=true, skips port scripts information in HTML/Markdown output")
6771
rootCmd.Flags().BoolVar(&config.OutputOptions.JSONPrettyPrint, "json-pretty", true, "--json-pretty=false (pretty prints JSON output)")
6872

6973
workflow = &formatter.MainWorkflow{}

formatter/output_options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ type OutputOptions struct {
66
SkipDownHosts bool
77
// JSONPrettyPrint defines if JSON output would be pretty-printed (human-readable) or not (machine readable)
88
JSONPrettyPrint bool
9+
// SkipSummary skips general summary for HTML & Markdown
10+
SkipSummary bool
11+
// SkipTraceroute skips traceroute information for HTML & Markdown
12+
SkipTraceroute bool
13+
// SkipMetrics skips metrics related data for HTML
14+
SkipMetrics bool
15+
// SkipPortScripts skips port scripts information for HTML
16+
SkipPortScripts bool
917
}

formatter/resources/templates/markdown.tmpl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
NMAP Scan Result: {{ .NMAPRun.StartStr }}
22
==========================================
33
{{- $displayDownHosts := not .OutputOptions.SkipDownHosts }}
4+
{{- $skipSummary := .OutputOptions.SkipSummary }}
5+
{{- $skipPortScripts := .OutputOptions.SkipPortScripts }}
46

57
## TOC
68

9+
{{- if not $skipSummary }}
710
* [Scan Summary](#scan-summary)
11+
{{- end }}{{/* if $skipSummary */}}
812
{{- range .NMAPRun.Host -}}
913
{{- if or ($displayDownHosts) (eq .Status.State "up") }}
1014
* [{{ .HostAddress.Address }}{{ range .HostNames.HostName }} / {{ .Name }}{{ end }} ({{ .Status.State }})](#{{ md_toc .HostAddress.Address }})
1115
{{- if eq .Status.State "up" }}
1216
* [Info](#{{ md_toc .HostAddress.Address }}-info)
1317
* [Ports](#{{ md_toc .HostAddress.Address }}-ports)
18+
{{- if not $skipPortScripts }}
1419
* [Scripts](#{{ md_toc .HostAddress.Address }}-scripts)
15-
{{ end }}
20+
{{- end -}}{{/* if not $skipPortScripts */}}
21+
{{- end }}
1622
{{- end -}}{{/* if or ($displayDownHosts) (eq .Status.State "up") */}}
1723
{{- end -}}{{/* range .Host */}}
1824

25+
{{- if not $skipSummary }}
1926
----
20-
2127
## Scan Summary
2228

2329
| Name | Value |
@@ -37,7 +43,7 @@ NMAP Scan Result: {{ .NMAPRun.StartStr }}
3743
| Exit (success) | {{ .NMAPRun.RunStats.Finished.Exit }} |
3844
| Summary | {{ .NMAPRun.RunStats.Finished.Summary }} |
3945
| Hosts | Up: {{ .NMAPRun.RunStats.Hosts.Up }}, Down: {{ .NMAPRun.RunStats.Hosts.Down }}, Total: {{ .NMAPRun.RunStats.Hosts.Total }} |
40-
46+
{{ end }}{{/* if not $skipSummary */}}
4147
----
4248

4349
{{ range .NMAPRun.Host -}}
@@ -75,6 +81,7 @@ NMAP Scan Result: {{ .NMAPRun.StartStr }}
7581
{{ range .Ports.Port -}}
7682
| {{ .PortID }} | {{ .Protocol }} | {{ .State.State }} | {{ .Service.Name }} | {{ .State.Reason }} | {{ .Service.Product }} | {{ .Service.Version }} | {{ .Service.ExtraInfo }} |
7783
{{ end }}{{/* range .Ports.Port */}}
84+
{{ if not $skipPortScripts }}
7885
<a id="{{ md_toc .HostAddress.Address }}-scripts"></a>
7986

8087
### Scripts:
@@ -90,6 +97,7 @@ NMAP Scan Result: {{ .NMAPRun.StartStr }}
9097

9198
{{- end -}}{{/* range .Script */}}
9299
{{- end -}}{{/* if .Script */}}
100+
{{ end -}}{{/* if not $skipPortScripts */}}
93101
{{ end -}}{{/* range .Ports.Port */}}
94102
{{- end -}}{{/* if eq .Status.State "up" */}}
95103

formatter/resources/templates/simple-html.gohtml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,23 @@
7878
</head>
7979
<body>
8080
{{ $displayDownHosts := not .OutputOptions.SkipDownHosts }}
81+
{{ $skipSummary := .OutputOptions.SkipSummary }}
82+
{{ $skipTraceroute := .OutputOptions.SkipTraceroute }}
83+
{{ $skipMetrics := .OutputOptions.SkipMetrics }}
84+
{{ $skipPortScripts := .OutputOptions.SkipPortScripts }}
8185
<h1>NMAP Scan Result: {{ .NMAPRun.StartStr }}</h1>
8286
<hr />
8387
<h2>TOC:</h2>
8488
<ul>
85-
<li><a href="#scan-summary">Scan Summary</a></li>
89+
{{ if not $skipSummary }}<li><a href="#scan-summary">Scan Summary</a></li>{{ end }}
8690
{{ range .NMAPRun.Host }}
8791
{{ if or ($displayDownHosts) (eq .Status.State "up") }}
8892
<li><a href="#{{ .HostAddress.Address }}">{{ .HostAddress.Address }}{{ range .HostNames.HostName }} / {{ .Name }}{{ end }}</a> ({{ .Status.State }})</li>
8993
{{ end }}{{/* if or ($displayDownHosts) (eq .Status.State "up") */}}
9094
{{ end }}{{/* range .Host */}}
9195
</ul>
9296
<hr />
97+
{{ if not $skipSummary }}
9398
<a name="scan-summary"></a>
9499
<h2>Scan Summary:</h2>
95100
<table id="summary-table">
@@ -162,6 +167,7 @@
162167
</tbody>
163168
</table>
164169
<hr />
170+
{{ end }}{{/* if not $skipSummary */}}
165171
{{ range .NMAPRun.Host }}
166172
{{ if or ($displayDownHosts) (eq .Status.State "up") }}
167173
<a name="{{ .HostAddress.Address }}"></a>
@@ -234,19 +240,19 @@
234240
<td>{{ .Service.Version }}</td>
235241
<td>{{ .Service.ExtraInfo }}</td>
236242
</tr>
237-
{{ if .Script }}
243+
{{ if and (.Script) (not $skipPortScripts) }}
238244
{{ range .Script }}
239245
<tr>
240246
<td></td>
241247
<td>{{ .ID }}</td>
242248
<td colspan="6"><pre>{{- .Output -}}</pre></td>
243249
</tr>
244250
{{ end }}{{/* range .Script */}}
245-
{{ end }}{{/* if .Script */}}
251+
{{ end }}{{/* if and (.Script) (not $skipPortScripts) */}}
246252
{{ end }}{{/* range .Ports.Port */}}
247253
</tbody>
248254
</table>
249-
{{ if .Trace }}
255+
{{ if and (.Trace) (not $skipTraceroute) }}
250256
<h3>Traceroute Information</h3>
251257
{{ if .Trace.Hops }}
252258
<details>
@@ -275,7 +281,8 @@
275281
{{ else }}
276282
No traceroute information.
277283
{{ end }}{{/* if .Trace.Hops */}}
278-
{{ end }}{{/* if .Trace */}}
284+
{{ end }}{{/* if and (.Trace) (not $skipTraceroute) */}}
285+
{{ if not $skipMetrics }}
279286
<h3>Misc Metrics</h3>
280287
<details>
281288
<summary>(open)</summary>
@@ -314,6 +321,7 @@
314321
</tbody>
315322
</table>
316323
</details>
324+
{{ end }}{{/* if not $skipMetrics */}}
317325
<hr />
318326
{{ end }}{{/* if eq .Status.State "up" */}}
319327
{{ end }}{{/* if or ($displayDownHosts) (eq .Status.State "up") */}}

0 commit comments

Comments
 (0)