Identifying the target to be scanned is an essential part of the Nmap tool and can be done in several different ways. In the simplest case, you can specify the IP address or network name to be scanned.
nmap www.hakatemia.fi
Sometimes you want to scan an entire network of hosts. For this, Nmap supports CIDR-style notation. You can add a prefix- notation to an IPv4 address or network name, and Nmap will scan each IP address in the specified range.
nmap 192.168.1.0/24 -> Scan all 256 addresses
The CIDR notation is concise, but not always flexible enough. In such cases, you can use octet class addressing. Instead of specifying a normal IP address, you can specify a comma-separated list of numbers or ranges for each octet.
nmap 192.168.1.1-180
nmap 192.162-168.1-254
You can specify multiple target hosts with the Nmap command, and they can be of different types.
nmap www.hakatemia.fi 192.168.0.0/8 192.162.1,2.0-255
Reading targets from the list (-iL)
To specify multiple targets for Nmap, you can create a list of targets in a file and then provide the filename to Nmap using the -iL option. The file can contain targets in any format acceptable on the Nmap command line (IP address, host name, CIDR, or octet ranges). Each target must be separated by one or more spaces, tabs, or line breaks.
nmap -iL from list-items.txt
Selecting targets randomly (-iR)
You may want to select targets randomly for internet-wide surveys. This can be done by using the -iR switch and providing the number of IP addresses to generate as an argument. Nmap automatically skips certain unwanted IP addresses such as private address ranges, multicast address ranges, or unused address ranges. An argument of 0 can also be given, in which case the scanning will continue indefinitely.
nmap -iR 10 -> Generate ten random IP addresses
Excluding Targets (--exclude, --excludefile)
Nmap offers the possibility to exclude certain targets from scanning using the "--exclude" or "--excludefile" switches. The "--exclude" switch can be used to exclude a single IP address or an entire network range from scanning. The "--excludefile" switch can be used to provide a file that contains individual IP addresses or network ranges to be excluded from scanning.
nmap --exclude 192.168.1.1-10,12 192.168.1.0/24
nmap --excludefile no-scan.txt -iL scan.txt
Which ports are not open on the target machine?


Ready to become an ethical hacker?
Start today.
As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.