Skip to content

Commit 8993f6c

Browse files
committed
#4: Add nmap-formatter examples with jq tool
1 parent b113043 commit 8993f6c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,50 @@ or Markdown
3939
nmap-formatter [path-to-nmap.xml] md > some-markdown.md
4040
```
4141

42+
or JSON
43+
44+
```
45+
nmap-formatter [path-to-nmap.xml] json
46+
```
47+
48+
it can be also combined with a `jq` tool, for example, list all the found ports and count them:
49+
50+
```
51+
nmap-formatter [nmap.xml] json | jq -r '.Host[]?.Ports?.Port[]?.PortID' | sort | uniq -c
52+
```
53+
54+
```
55+
1 "22"
56+
2 "80"
57+
1 "8080"
58+
```
59+
60+
another example where only those hosts are selected, which have port where some http service is running:
61+
62+
```
63+
nmap-formatter [nmap.xml] json | jq '.Host[]? | . as $host | .Ports?.Port[]? | select(.Service.Name== "http") | $host.HostAddress.Address' | uniq -c
64+
```
65+
66+
```
67+
1 "192.168.1.1"
68+
1 "192.168.1.2"
69+
2 "192.168.1.3"
70+
```
71+
72+
In this case `192.168.1.3` has 2 http services running (for example on ports 80 and 8080)`.
73+
74+
Another example where it is needed to display only filtered ports:
75+
76+
```
77+
nmap-formatter [nmap.xml] json | jq '.Host[]?.Ports?.Port[]? | select(.State.State == "filtered") | .PortID'
78+
```
79+
80+
Display host IP addresses that have filtered ports:
81+
82+
```
83+
nmap-formatter [nmap.xml] json | jq '.Host[]? | . as $host | .Ports?.Port[]? | select(.State.State == "filtered") | .PortID | $host.HostAddress.Address'
84+
```
85+
4286
### Flags
4387

4488
* `-f, --file [filename]` outputs result to the file (by default output goes to STDOUT)

0 commit comments

Comments
 (0)