Skip to content

Nmap

Terminal window
nmap [scan type] [options] <target>

Targets can be IPs (10.10.10.1), ranges (10.10.10.1-50), CIDR (10.10.10.0/24), or hostnames (example.com). Multiple targets separated by spaces.


FlagScanNotes
-sSTCP SYN (stealth)Default with root. Half-open — doesn’t complete handshake.
-sTTCP connectFull handshake. Default without root. Slower, logged by target.
-sUUDPSlow. Combine with -sS for both protocols.
-snPing sweep (no port scan)Host discovery only.
-sVVersion detectionProbes open ports for service/version info.
-sAACK scanMaps firewall rules (filtered vs unfiltered).
-sN / -sF / -sXNull / FIN / XmasStealth scans exploiting RFC 793. Unreliable on Windows.

FlagPurpose
-p 22,80,443Scan specific ports
-p-Scan all 65535 ports
-p 1-1000Scan port range
--top-ports 100Scan the N most common ports
-OOS detection
-AAggressive: OS detection + version + scripts + traceroute
-T0 to -T5Timing template (0=paranoid, 3=default, 5=insane)
-oN fileNormal output to file
-oX fileXML output
-oG fileGrepable output
-oA basenameAll three output formats
-v / -vvVerbose / very verbose
--openOnly show open ports
-PnSkip host discovery (treat host as online)
-nNo DNS resolution
--reasonShow why a port is in a particular state

Terminal window
nmap -sS -p- --min-rate 5000 -oN full-scan.txt 10.10.10.x

Finds all open TCP ports quickly. Follow up with targeted version/script scans on discovered ports.

Terminal window
nmap -sCV -p 22,80,443,8080 -oN services.txt 10.10.10.x

-sCV is shorthand for -sC -sV — runs default scripts and version detection on the specified ports.

Terminal window
sudo nmap -sU --top-ports 50 --min-rate 3000 -oN udp.txt 10.10.10.x

UDP is slow — limit to top ports unless you have time. Requires root.

Terminal window
nmap -sn 10.10.10.0/24 -oG hosts.txt

Quick ping sweep. Grepable output is easy to parse for live hosts:

Terminal window
grep "Up" hosts.txt | awk '{print $2}'

Nmap Scripting Engine — hundreds of scripts for enumeration, vuln scanning, brute forcing.

Terminal window
# Run default scripts
nmap -sC 10.10.10.x
# Run specific script
nmap --script http-enum 10.10.10.x
# Run script category
nmap --script vuln 10.10.10.x
# Script with arguments
nmap --script http-brute --script-args http-brute.path=/admin 10.10.10.x
CategoryPurpose
defaultSafe, general-purpose enumeration
vulnVulnerability checks
safeWon’t crash services or exploit anything
intrusiveMay crash services — use with caution
discoveryService and host discovery
authAuthentication checks
bruteBrute-force attacks

List all scripts: ls /usr/share/nmap/scripts/

Search scripts: grep -l "smb" /usr/share/nmap/scripts/*.nse


Save everything with -oA — you’ll want the grepable and XML formats later:

Terminal window
nmap -sCV -p- -oA full-scan 10.10.10.x

This creates full-scan.nmap, full-scan.gnmap, and full-scan.xml.

Converting XML to HTML report
Terminal window
xsltproc full-scan.xml -o report.html

Or use nmap’s built-in stylesheet:

Terminal window
xsltproc /usr/share/nmap/nmap.xsl full-scan.xml -o report.html