目录导航
nmap-formatter简介
一个允许您将 NMAP XML 输出转换为 html/csv/json/markdown 的工具。
用法
nmap-formatter [path-to-nmap.xml] [html|csv|md|json] [flags]
将 XML 输出转换为更好的 HTML
nmap-formatter [path-to-nmap.xml] html > some-file.html
或转换为markdown
nmap-formatter [path-to-nmap.xml] md > some-markdown.md
或 JSON
nmap-formatter [path-to-nmap.xml] json
它也可以与jq
工具结合使用,例如,列出所有找到的端口并计算它们:
nmap-formatter [nmap.xml] json | jq -r '.Host[]?.Ports?.Port[]?.PortID' | sort | uniq -c
1 "22"
2 "80"
1 "8080"
另一个示例,其中仅选择了那些具有运行某些 http 服务的端口的主机:
nmap-formatter [nmap.xml] json | jq '.Host[]? | . as $host | .Ports?.Port[]? | select(.Service.Name== "http") | $host.HostAddress.Address' | uniq -c
1 "192.168.1.1"
1 "192.168.1.2"
2 "192.168.1.3"
在这种情况下192.168.1.3
,有 2 个 http 服务正在运行(例如在端口 80 和 8080 上)`。
另一个需要仅显示过滤端口的示例:
nmap-formatter [nmap.xml] json | jq '.Host[]?.Ports?.Port[]? | select(.State.State == "filtered") | .PortID'
显示具有过滤端口的主机 IP 地址:
nmap-formatter [nmap.xml] json | jq '.Host[]? | . as $host | .Ports?.Port[]? | select(.State.State == "filtered") | .PortID | $host.HostAddress.Address'
flag
-f, --file [filename]
将结果输出到文件(默认输出到 STDOUT)--help
显示帮助信息--version
显示版本(也可以使用./nmap-formatter version
:)
输出相关标志
--skip-down-hosts
跳过关闭的主机- 适用于:
html
,md
,csv
- 默认:
true
- 适用于:
--skip-summary
跳过汇总表- 适用于:
html
,md
- 默认:
false
- 适用于:
--skip-traceroute
跳过跟踪路由信息- 适用于:
html
- 默认:
false
- 适用于:
--skip-metrics
跳过指标信息- 适用于:
html
- 默认:
false
- 适用于:
--skip-port-scripts
跳过端口表中的端口脚本信息- 适用于:
html
,md
- 默认:
false
- 适用于:
--json-pretty
漂亮打印 JSON- 适用于:
json
- 默认:
true
- 适用于:
安装
使用go
go install github.com/vdjagilev/nmap-formatter@latest
docker
无需安装,只需运行docker run
:
docker run -v /path/to/xml/file.xml:/opt/file.xml ghcr.io/vdjagilev/nmap-formatter:latest /opt/file.xml json
下载二进制
从发布页面选择版本并下载:
curl https://github.com/vdjagilev/nmap-formatter/releases/download/v0.3.1/nmap-formatter-linux-amd64.tar.gz --output nmap-formatter.tar.gz -L
tar -xzvf nmap-formatter.tar.gz
./nmap-formatter --help
编译
git clone [email protected]:vdjagilev/nmap-formatter.git
cd nmap-formatter
go mod tidy
go build
# or
go run . path/to/nmap.xml html
例子
从 ( https://nmap.org/book/output-formats-xml-output.html )生成的 HTML 输出示例
nmap-formatter basic-example.xml html

作为library使用
如何使用 golang 解析 nmap 结果
package main
import (
"encoding/xml"
"os"
"github.com/vdjagilev/nmap-formatter/formatter"
)
func main() {
var nmap formatter.NMAPRun
var config formatter.Config = formatter.Config{}
// Read XML file that was produced by nmap (with -oX option)
content, err := os.ReadFile("example.xml")
if err != nil {
panic(err)
}
// Unmarshal XML and map structure(s) fields accordingly
if err = xml.Unmarshal(content, &nmap); err != nil {
panic(err)
}
// Output data to console stdout
// You can use any other io.Writer implementation
// for example: os.OpenFile("file.json", os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
config.Writer = os.Stdout
// Formatting data to JSON, you can use:
// CSVOutput, MarkdownOutput, HTMLOutput as well
config.OutputFormat = formatter.JSONOutput
// Setting formatter data/options
templateData := formatter.TemplateData{
NMAPRun: nmap, // NMAP output data itself
OutputOptions: formatter.OutputOptions{
JSONPrettyPrint: true, // Additional option to prettify JSON
},
}
// New formatter instance
formatter := formatter.New(&config)
if formatter == nil {
// Not json/markdown/html/csv
panic("wrong formatter provided")
}
// Attempt to format the data
if err = formatter.Format(&templateData); err != nil {
// html template could not be parsed or some other issue occured
panic(err)
}
}
下载地址:
- nmap-formatter-darwin-amd64.zip2.47 MB
- nmap-formatter-darwin-arm64.zip2.38 MB
- nmap-formatter-linux-amd64.tar.gz2.49 MB
- nmap-formatter-linux-arm64.tar.gz2.32 MB
- nmap-formatter-windows-amd64.zip2.54 MB
- nmap-formatter-windows-arm64.zip2.37 MB
项目地址
GitHub:https://github.com/vdjagilev/nmap-formatter
转载请注明出处及链接