Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 ยท Projects and Practice

Nmap Practice Exercises and Cheat Sheet

Review Nmap with a compact command cheat sheet, scenario exercises with solutions, a command explainer in Python and a mixed self-test for the whole course.

You have now seen the whole workflow: discover hosts, scan ports, detect services and systems, run scripts, tune timing, respect the law and report results. This last lesson helps you review. It gives you a compact cheat sheet, scenario exercises with solutions, a small tool that explains a command line option by option and a final self-test.

As always, practise only on your own machine, a home lab or documentation ranges. All commands below are written for the reserved example addresses.

Cheat sheet

Targets

Goal Command part
One host nmap 192.0.2.10
A range nmap 192.0.2.1-50
A subnet nmap 192.0.2.0/24
From a file -iL targets.txt
Exclude --exclude 192.0.2.10 or --excludefile file

Discovery and ports

Goal Option
Discovery only (no port scan) -sn
Skip discovery, treat host as up -Pn
No DNS lookups -n
Specific ports -p 22,80,443 or -p 1-1024
All ports -p-
Top N ports --top-ports 100, or -F for 100
TCP SYN scan (needs privileges) -sS
TCP connect scan (no privileges) -sT
UDP scan -sU
Show only open ports --open
Explain states --reason

Detection and scripts

Goal Option
Service/version -sV (--version-intensity 0-9)
Operating system -O
Default scripts -sC
Chosen scripts --script name,category,"expr"
Script arguments / help --script-args k=v / --script-help name
All of the above plus traceroute -A

Speed, output and safety

Goal Option
Timing template -T0 to -T5 (default -T3)
Hard speed limit --max-rate 100
Limit time per host --host-timeout 10m
Save everything -oA basename
XML / normal / grepable -oX / -oN / -oG
Compare scans ndiff old.xml new.xml
More information while running -v, -vv, -d

Explain a command with code

A good way to check your understanding is to explain a command line option by option. The tool below does that for the options in the cheat sheet. Add your own entries, and try it on commands you meet.

Python Command explainer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Scenario exercises

Try to answer each before reading the solution. Use documentation addresses only.

1. The new server. You installed a web server on 192.0.2.50 and want to confirm that only SSH, HTTP and HTTPS are reachable, then save the result in all formats.

Solution. sudo nmap -sS -sV -p- --open -oA scans/web50 192.0.2.50 checks all ports. The --open option lists only open ones. Compare the list with the three expected ports, and investigate anything extra. For a quick check use --top-ports 1000 instead of -p-.

2. Which hosts are up? List the live hosts in 192.0.2.0/24 without scanning ports.

Solution. nmap -sn 192.0.2.0/24. On the local network Nmap uses ARP, which is reliable; across routers it uses ICMP and TCP probes, so some hosts may stay hidden by firewalls (then try -Pn on known addresses).

3. Find old SSH. You need a list of hosts whose SSH server is older than 8.0.

Solution. Scan port 22 with version detection and XML output: nmap -p 22 -sV --open -oX ssh.xml 192.0.2.0/24. Then parse the file with the code from Parsing XML Output and filter versions, remembering that vendor backports can make an old number safe.

4. A fragile printer. The printer at 192.0.2.12 crashed during a previous scan. How do you check it more gently?

Solution. Scan only the needed ports with a gentle template and a limit: nmap -sT -T2 --max-rate 10 -p 631,9100 192.0.2.12, outside working hours and after informing the owner. Avoid -A, -O and intrusive scripts, see Timing.

5. Weekly monitoring. Describe how you would detect new open ports on the office network each week.

Solution. Schedule a scoped scan with dated -oA output, compare XML with the previous run using ndiff or your own code, classify changes by severity, and alert only on meaningful ones. Also alert if the scan itself fails. See Automating Scans.

6. Permission. A friend says "scan my company website, they will never notice". What do you answer?

Solution. Do not. Scanning without written authorisation from the company can be illegal and can harm your friend's career and yours. Ask for a signed scope, as described in Legal and Ethical Scanning, or practise on your own lab.

Mini-challenge: build your own cheat sheet check

Python Which option answers which question?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Where to go next

  • Re-read the earlier chapters on target selection and scan types and try each option on your own machine and lab.
  • Study the official Nmap documentation and the Nmap Network Scanning book for the deepest detail.
  • Learn packet analysis with a protocol analyser, so you can watch what Nmap sends.
  • Explore related topics: firewalls, intrusion detection, vulnerability management and secure configuration.

Final self-test

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which option scans all 65,535 TCP ports?

    -p- is shorthand for -p 1-65535. -F scans only 100 ports and -sn skips port scanning.
  2. 2. Which pair tells you what runs on a port and which operating system the host probably uses?

    -sV identifies services and versions, -O guesses the operating system.
  3. 3. What is the safest default when you are unsure whether you may scan a network?

    Permission is the condition that matters. Technical options do not replace it.
  4. 4. Why save results with -oA?

    You get a readable file, a structured XML master and a grepable file without scanning again.
  5. 5. What does a NSE script in the 'safe' category promise?

    safe scripts are designed not to harm the target, which makes them suitable for routine checks.

Summary

  • Keep the cheat sheet near: targets, discovery, ports, detection, scripts, speed and output.
  • Practise with scenarios: reason from the goal to the option, then to the result.
  • Safety and permission come before technique, always.
  • You can now plan, run, interpret, automate and report network scans responsibly.

Next: back to the Nmap track page