masscan
An asynchronous port scanner that sweeps enormous address ranges in minutes, then hands the live hosts to nmap for the detailed work.
Authorized use only. Run these only on systems you own or have explicit written permission to test. Full notice at the foot of the page.
01Why masscan exists
nmap is thorough but sends packets and waits for each reply, which is slow across large ranges. masscan takes the opposite approach: it fires packets as fast as the link allows and matches replies asynchronously, with its own TCP/IP stack. The author describes it as able to scan the entire IPv4 internet in minutes from a fast connection. You do not use it instead of nmap; you use it to find the few live ports in a huge space, then point nmap at those.
02Install
$ sudo emerge net-analyzer/masscan # Gentoo
$ sudo apt install masscan # Debian / Ubuntu / Kali
$ sudo dnf install masscan # Fedora / RHEL
03A basic scan
The syntax looks like nmap on purpose, but the rate flag is the one that matters: it sets packets per second, and it is the dial between speed and politeness. Start low on anything shared. Running raw sockets needs root.
$ sudo masscan 10.0.0.0/24 -p80,443,22,8080 --rate 1000
04Sweeping all ports fast
To find anything listening anywhere, scan the full port range. This is where masscan earns its name; the same sweep in nmap would take far longer. Keep the rate sane so you do not melt a switch or trip an IDS.
$ sudo masscan 10.0.0.0/24 -p0-65535 --rate 5000 -oL sweep.txt
» Higher --rate is faster but drops more replies and is louder. On a home lab 1000-5000 is plenty; reserve big rates for links you own end to end.
05Excluding what you must not touch
On a real engagement there are addresses you are told to leave alone. masscan takes an exclude file, and honouring it is part of staying inside scope.
$ sudo masscan 10.0.0.0/16 -p443 --rate 2000 --excludefile scope-exclude.txt
06Output formats
masscan writes several machine-readable formats. The list format is human-readable; the grepable and JSON forms feed scripts; and there is a mode that emits nmap-style XML. Pick the one your next step wants.
$ sudo masscan 10.0.0.0/24 -p1-65535 --rate 3000 -oG masscan.gnmap
$ sudo masscan 10.0.0.0/24 -p1-65535 --rate 3000 -oJ masscan.json
07The classic masscan-then-nmap pipeline
This two-step is the point of the tool. masscan finds the open ports across the whole range quickly; then you feed just those hosts and ports to nmap for service and version detection, which is the slow part you only want to run where something is actually listening.
$ sudo masscan 10.0.0.0/24 -p1-65535 --rate 3000 -oL sweep.txt
$ awk '/open/{print $4}' sweep.txt | sort -u > live-hosts.txt
$ nmap -sV -iL live-hosts.txt
» Fast and wide first, slow and deep second. That split is how you scan a large space without waiting all day or hammering every host with full version detection.
08What a masscan sweep teaches the owner
Run masscan against your own range and the open-port list is your external attack surface at a glance: every service exposed, including the ones nobody remembered leaving on. That is the real value here. Close what should not be reachable, firewall what should be internal, and re-scan to confirm.
» Unexpected open ports are the finding; a forgotten admin panel or database port is exactly how intrusions start.
» A sudden full-range SYN sweep at high rate is an obvious signature in firewall and IDS logs; knowing it helps you recognise it against your own network.
» Re-run after any firewall change to confirm the surface shrank the way you intended.
Point masscan only at ranges you own or are authorized to assess. Its speed makes an out-of-scope scan both easy to launch and easy to trace back to you.
Authorized use only
The tools and techniques in these guides are for defending, testing, and understanding systems you own or have explicit written permission to assess. Unauthorized access to computers, networks, accounts, or data is a criminal offense in nearly every jurisdiction, and the penalties are real.
A few of the laws that apply, by way of example:
- Philippines: Cybercrime Prevention Act of 2012 (Republic Act No. 10175)
- United States: Computer Fraud and Abuse Act (18 U.S.C. § 1030)
- United Kingdom: Computer Misuse Act 1990
- European Union: Directive 2013/40/EU on attacks against information systems, as implemented by each member state
- Most other countries have equivalent computer-misuse laws
Wherever you are, the rule is the same: get authorization in writing, stay within the agreed scope, and never touch a system that is not yours to test. If you are unsure whether something is permitted, treat it as not permitted until you have clear authorization.
This is general information, not legal advice.