Skip to content

/errors/nmap/no-targets-were-specified-so-0-hosts-scanned

WARNING: No targets were specified, so 0 hosts scanned.

The commands on this page have not been executed by our verification runner yet.updated
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 warningCause
Failed to resolve "NAME".The name did not resolve: fix the name or use the IP address
NothingNo target on the command line, an empty variable, or an empty -iL file
Nothing, and --exclude or --excludefile is usedThe exclusions removed every target

Correct commands

bash
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 file

scanme.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

bash
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.

Sources