Skip to content

Commit

Permalink
#7: Rename down-hosts output option
Browse files Browse the repository at this point in the history
  • Loading branch information
vdjagilev committed Jul 8, 2021
1 parent 2ed873e commit 7bdedf6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ nmap-formatter [path-to-nmap.xml] md > some-markdown.md

### Flags

* `--down-hosts` includes hosts that are down in the template (html, md)
* `-f, --file [filename]` outputs result to the file (by default output goes to STDOUT)
* `--help` display help message

#### Output Related Flags

* `--skip-down-hosts` skips hosts that are down
* Applicable in: `html`, `md`, `csv`
* Default: `true`

## Installation

### Using Go
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func init() {
log.SetOutput(os.Stderr)

rootCmd.Flags().StringVarP((*string)(&config.OutputFile), "file", "f", "", "-f output-file (by default \"\" will output to STDOUT)")
rootCmd.Flags().BoolVar(&config.OutputOptions.DisplayDownHosts, "down-hosts", false, "--down-hosts=true")
rootCmd.Flags().BoolVar(&config.OutputOptions.SkipDownHosts, "skip-down-hosts", true, "--skip-down-hosts=false")
}

// validate is checking input from the command line
Expand Down
2 changes: 1 addition & 1 deletion formatter/formatter_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (f *CSVFormatter) convert(td *TemplateData) (data [][]string) {
data = append(data, []string{"IP", "Port", "Protocol", "State", "Service", "Reason", "Product", "Version", "Extra info"})
for _, host := range td.NMAPRun.Host {
// Skipping hosts that are down
if !td.OutputOptions.DisplayDownHosts && host.Status.State != "up" {
if td.OutputOptions.SkipDownHosts && host.Status.State != "up" {
continue
}
address := fmt.Sprintf("%s (%s)", host.HostAddress.Address, host.Status.State)
Expand Down
2 changes: 1 addition & 1 deletion formatter/output_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package formatter
// OutputOptions describes various output options for nmap formatter
type OutputOptions struct {
// The hosts that are down wont be displayed in the TOC
DisplayDownHosts bool
SkipDownHosts bool
}
2 changes: 1 addition & 1 deletion formatter/resources/templates/markdown.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NMAP Scan Result: {{ .NMAPRun.StartStr }}
==========================================
{{- $displayDownHosts := .OutputOptions.DisplayDownHosts }}
{{- $displayDownHosts := not .OutputOptions.SkipDownHosts }}

## TOC

Expand Down
2 changes: 1 addition & 1 deletion formatter/resources/templates/simple-html.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</style>
</head>
<body>
{{ $displayDownHosts := .OutputOptions.DisplayDownHosts }}
{{ $displayDownHosts := not .OutputOptions.SkipDownHosts }}
<h1>NMAP Scan Result: {{ .NMAPRun.StartStr }}</h1>
<hr />
<h2>TOC:</h2>
Expand Down

0 comments on commit 7bdedf6

Please # to comment.