/errors/nmap/no-targets-were-specified-so-0-hosts-scanned
WARNING: No targets were specified, so 0 hosts scanned.
- tool
- Nmap
- exit code
- 0
- versions
- Nmap 7.x
- os
- linux, macos, windows
WARNING: No targets were specified, so 0 hosts scanned. means nmap finished without a single host to scan: you gave no target, every target failed to resolve or was excluded, or the target list was empty. nmap prints it at the end of the run and exits with status 0. Look for Failed to resolve lines above it, then make sure the command ends with a valid target after all options, for example nmap -p 80,443 scanme.nmap.org.
Where the message comes from
printfinaloutput() in nmap's output.cc prints the warning when the number of scanned hosts is zero, so it appears for every cause that leaves no target. The causes leave different traces:
| What you see above the warning | Cause |
|---|---|
| Failed to resolve "NAME". | The name did not resolve: fix the name or use the IP address |
| Nothing | No target on the command line, an empty variable, or an empty -iL file |
| Nothing, and --exclude or --excludefile is used | The exclusions removed every target |
Correct commands
nmap scanme.nmap.org # target at the end
nmap -p 22,80,443 scanme.nmap.org # -p has its own value
nmap -sn 192.0.2.0/24 # a range
nmap -iL targets.txt -p 443 # targets from a filescanme.nmap.org is the host the Nmap project provides for test scans; replace the documentation range 192.0.2.0/24 with a network you are authorised to scan.
In scripts
host="${1:?usage: scan.sh HOST}"
nmap -sV -oX scan.xml "$host"${1:?...} stops the script with a message when no argument was given, instead of running nmap without a target. Because nmap exits with status 0 in this case, check the XML or grepable output for hosts instead of relying on the exit code.