Use, on macOS/Linux, the nmap
command to scan open ports (e.g., github.com
) and retrieve the results in a valid JSON format using xml2json
and jq
.
- Install
xml2json
withnpm install -g xml2json-command
(NodeJS required!) - Install
jq
withbrew install jq
(Homebrew required)
Arg | Function |
---|---|
sudo | This command needs to run as root |
nmap | Launch the Nmap network scanning tool |
-sS | Use TCP SYN scan to discover open ports |
-Pn | Treat all hosts as online (skip host discovery) |
-p | Specify the ports to scan (comma-separated list) |
22, 80, 443, 21, 25, 110, 143, 53, 3389, 3306, 5432, 23, 161, 162, 5900 | List of ports to scan |
-oX - | Output the results in XML format to standard output (stdout) |
github.com | The target hostname or IP address to scan |
sudo nmap \
-sS \
-Pn \
-p 22, 80, 443, 21, 25, 110, 143, 53, 3389, 3306, 5432, 23, 161, 162, 5900 \
-oX - github.com | \
env NODE_OPTIONS="--no-deprecation" \
xml2json \
-t xml2json | \
jq .
sudo nmap \
-sS \
-Pn \
-p 22,80,443,21,25,110,143,53,3389,3306,5432,23,161,162,5900 \
-oX - \
github.com \
-d 2 \ # Debug level 2
-v 1 \ # Verbosity level 1
| env NODE_OPTIONS="--no-deprecation" xml2json -t xml2json \
| jq .
{
"$c": "Nmap 7.94 scan initiated Thu Jan 25 08:38:53 2024 as: nmap -sS -Pn -p 22,80,443,21,25,110,143,53,3389,3306,5432,23,161,162,5900 -oX - -d -v github.com 2 1",
"nmaprun": {
"scanner": "nmap",
"args": "nmap -sS -Pn -p 22,80,443,21,25,110,143,53,3389,3306,5432,23,161,162,5900 -oX - -d -v github.com 2 1",
"start": "1706168333",
"startstr": "Thu Jan 25 08:38:53 2024",
"version": "7.94",
"xmloutputversion": "1.05",
"scaninfo": {
"type": "syn",
"protocol": "tcp",
"numservices": "15",
"services": "21-23,25,53,80,110,143,161-162,443,3306,3389,5432,5900"
},
"verbose": {
"level": "2"
},
"debugging": {
"level": "1"
},
"taskbegin": [
{
"task": "Parallel DNS resolution of 3 hosts.",
"time": "1706168333"
},
{
"task": "SYN Stealth Scan",
"time": "1706168333"
}
],
...
}