Skip to content

Templates

Vsevolod Djagilev edited this page May 2, 2022 · 3 revisions

You can use your own custom templates (HTML or Markdown) for the output. Basic example is shown here:

NB! Be careful in using custom templates and parsing unverified data, even though golang template engine has certain protection measures against XSS in HTML templates, it's still advised to be vigilant about the data from unknown sources and templates from unknown sources. Review them carefully.

Markdown

Template:

# Scanning

{{ range .NMAPRun.Host }}
{{ if eq .Status.State "up" }}
## {{ .HostAddress.Address }}
---
{{ range .Port }}
* {{ .PortID }} ({{ .Protocol }})
{{ end }}
{{ end }}
{{ end }}

Command:

nmap-formatter md example.xml --md-use-template example.md

Output:

# Scanning

## 74.207.244.221
---
* 22 (tcp)
* 80 (tcp)

HTML

Template:

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        {{ range .NMAPRun.Host }}
            {{ if eq .Status.State "up" -}}
            <h2>{{ .HostAddress.Address }}</h2>
            <hr />
            <ul>
                {{ range .Port -}}
                <li>{{ .PortID }} ({{ .Protocol }})</li>
                {{ end }}
            </ul>
            {{- end }}
        {{- end }}
    </body>
</html>

Command:

nmap-formatter html example.xml --html-use-template template.html > example.html

Output:

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        
            <h2>74.207.244.221</h2>
            <hr />
            <ul>
                <li>22 (tcp)</li>
                <li>80 (tcp)</li>
                
            </ul>
    </body>
</html>
Clone this wiki locally