## TL;DR
--top-ports was added in nmap 6.01, so anything older rejects it as an invalid argument. Upgrade nmap if you can. If you are stuck on the old build, pass an explicit common-port list or use -F for the fast scan, which approximates the same idea.

```text
nmap: invalid argument to --top-ports
```

## Use this when
- nmap rejects --top-ports immediately at argument parsing.
- `nmap --version` shows a build older than 6.01.
- You need a short, high-value port list.

## Not for this skill when
- The scan starts. Then the flag parsed fine and something else broke.
- You can upgrade. Just upgrade instead of working around.

## Steps
1. Check the version: `nmap --version`. Verify: you confirm the build predates --top-ports support.
2. Upgrade through your package manager if the engagement allows it. Verify: `nmap --version` shows 7.x and --top-ports parses.
3. If you cannot upgrade, emulate it with an explicit list: `nmap -p 21,22,23,25,53,80,110,111,135,139,143,443,445,993,995,1723,3306,3389,5900,8080 192.0.2.5`. Verify: the scan runs and covers the common services.
4. Or use the fast scan, which is the old build's built-in shortcut: `nmap -F 192.0.2.5`. Verify: the run completes quickly over the default fast port set.
5. Note the nmap version in your report methodology. Verify: anyone reproducing your work knows the exact build.

Compatibility: the workaround applies to nmap 5.x and older. Current 7.x builds accept --top-ports natively.

## Variant phrasings
### nmap top-ports invalid argument
Same fix path, common phrasing.
### nmap old version top ports not supported
The version-flavored search.
### nmap -F vs --top-ports
The alternative-flag search.

## Why it happens
--top-ports reads nmap's frequency-ranked port table, a feature added in 6.01. Older parsers do not know the flag and reject the whole argument line. Enterprise jump boxes and old Kali images still ship these builds.

## Edge cases / pitfalls
- An explicit -p list is static. --top-ports 1000 on a modern build adapts to the frequency table; your list will not.
- -F scans 100 ports, roughly --top-ports 100. Do not treat it as full coverage.
- Upgrading mid-engagement changes fingerprints and script behavior. Note the version change in your report.
- Old builds also lack newer NSE scripts. If scripts matter, upgrade rather than workaround.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_pnnZlf4Vk9znIA2jS1wfDQ
