masscan + fping + arp-scan
Three fast discovery tools: masscan is a stateless port scanner that can sweep huge ranges in minutes, fping pings many hosts at once, and arp-scan finds the IP and MAC of every device on the local LAN using ARP. Scan only your own network or with written permission.
76.1 Why is it used?
- masscan: find open ports across big address ranges quickly (masscan 192.168.96.0/24 -p80).
- fping: ping sweep a subnet to see which hosts are alive (fping -a -g 192.168.96.0/24).
- arp-scan: list every device on the same LAN with IP + MAC, even when ICMP is blocked (arp-scan --localnet).
- Install from apt on Linux, brew on macOS; on Windows use WSL (masscan also has a native build with Npcap).
76.2 How they work
- Step 1
1.Scanner 192.168.96.5 sends SYN :80 through the Docker bridge to web
- Step 2
2.Without waiting, the next SYN goes to DB :3306
- Step 3
3.web replies SYN-ACK; masscan marks 80/tcp open
- Step 4
4.masscan sends RST and closes it at once
- Step 5
5.No connection table: replies are matched by a cookie in the sequence number
A separate receive thread collects replies while the sender keeps transmitting
- Step 1
1.arp-scan broadcasts: who has 192.168.96.10?
- Step 2
2.The Docker bridge floods the frame out of every port
- Step 3
3.Only the owner of that IP replies with its MAC
- Step 4
4.arp-scan builds an IP -> MAC table
- Step 5
5.ARP does not cross a router: local network only
- fping sends ICMP echo round-robin: web, then DB, then .40 without stopping; replies mark hosts alive, silence marks .40 unreachable.
76.3 masscan: targets, ports and rate
- -sL sends nothing and prints the targets in random order.
- Targets: IPs, start-end ranges and CIDRs, mixed with commas or spaces; --exclude / --excludefile keep hosts out.
- Ports: -p22,80, -p 20-25, U:161 for UDP.
- Default rate is only 100 packets/s; --rate raises it, but a high rate can overload a network and miss replies.
- --retries 1 sends each probe once more, --wait 2 listens 2 s for late replies, --ping sends ICMP echo (shown as port 0/icmp).
masscan 192.168.96.8/30 -sLmasscan 192.168.96.0/27 -p22,80,443,3306 --exclude 192.168.96.1 --wait 2masscan 192.168.96.0/27 --ping --rate 50 --retries 1 --wait 2 --exclude 192.168.96.1$ masscan 192.168.96.8/30 -sL192.168.96.11192.168.96.8192.168.96.10192.168.96.9$ masscan 192.168.96.0/27 -p22,80,443,3306 --exclude 192.168.96.1 --wait 2Initiating SYN Stealth ScanScanning 31 hosts [4 ports/host]Discovered open port 22/tcp on 192.168.96.10Discovered open port 80/tcp on 192.168.96.10Discovered open port 3306/tcp on 192.168.96.20$ masscan 192.168.96.0/27 --ping --rate 50 --retries 1 --wait 2 --exclude 192.168.96.1Initiating ICMP Echo ScanScanning 31 hostsDiscovered open port 0/icmp on 192.168.96.30Discovered open port 0/icmp on 192.168.96.20Discovered open port 0/icmp on 192.168.96.1076.4 masscan: adapter, packet trace and banners
- --packet-trace prints every packet: closed 443 gives RST-ACK, open 80 gives SYN-ACK, and masscan answers both with RST.
- The source port is random; --adapter-port 61000 fixes it. -e picks the interface, --adapter-ip the source IP.
- --banners talks to open ports, but the Linux kernel does not know masscan's connection and would RST it, so use a spare unused --adapter-ip.
masscan 192.168.96.10 -p80,443 --wait 1 --packet-tracemasscan 192.168.96.10 -p22,80 --banners --adapter-ip 192.168.96.200 --wait 3$ masscan 192.168.96.10 -p80,443 --wait 1 --packet-traceSENT (0.4109) TCP [192.168.96.5]:54857 > [192.168.96.10]:443 SYNRCVD (0.4405) TCP [192.168.96.10]:443 > [192.168.96.5]:54857 RST-ACKSENT (0.4404) TCP [192.168.96.5]:54857 > [192.168.96.10]:443 RSTSENT (0.4405) TCP [192.168.96.5]:54857 > [192.168.96.10]:80 SYNRCVD (0.4409) TCP [192.168.96.10]:80 > [192.168.96.5]:54857 SYN-ACKDiscovered open port 80/tcp on 192.168.96.10SENT (0.4413) TCP [192.168.96.5]:54857 > [192.168.96.10]:80 RST$ masscan 192.168.96.10 -p22,80 --banners --adapter-ip 192.168.96.200 --wait 3Discovered open port 22/tcp on 192.168.96.10Discovered open port 80/tcp on 192.168.96.10Banner on port 22/tcp on 192.168.96.10: [ssh] SSH-2.0-n076labBanner on port 80/tcp on 192.168.96.10: [http.server] SimpleHTTP/0.6 Python/3.12.3Banner on port 80/tcp on 192.168.96.10: [title] n076 lab76.5 masscan: output, shards and config files
| Option | Effect |
|---|---|
| -oL file | Simple list: one open port + IP per line |
| -oB file | Compact binary (243 bytes in the lab); convert later with --readscan |
| -oJ / -oX / -oG | JSON / XML (default format) / grepable |
| --open-only | Report only open ports |
| --rotate hourly | Rotate the output file in long scans |
| --shards 1/2 --seed 7 | Split a scan across machines (all shards need the same seed) |
| --echo > f / -c f | Dump settings to a config file / load it |
| --resume paused.conf | Continue after Ctrl+C |
masscan 192.168.96.0/27 -p22,80,3306 --exclude 192.168.96.1 --wait 2 -oL scan.txt --open-onlycat scan.txtmasscan 192.168.96.0/29 -sL --shards 1/2$ cat scan.txt#masscanopen tcp 22 192.168.96.10 1794174890open tcp 3306 192.168.96.20 1794174890open tcp 80 192.168.96.10 1794174891# end$ masscan 192.168.96.0/29 -sL --shards 1/2[-] WARNING: --seed <num> is not specified HINT: all shards must share the same seed192.168.96.4192.168.96.5192.168.96.0192.168.96.1- Lab notes: the --echo config had a nocapture line this version could not read back (removed with grep -v); --regress passed, --offline failed with 'bad packet template'.
76.6 fping: targets and output
- -g CIDR or -g start end generates targets; targets can also come from stdin or -f file.
- -a only alive hosts, -u only unreachable, -e adds RTT, -n / -A show name / IP, -s prints stats.
- -x 2 succeeds only if at least 2 hosts are reachable.
- -r retries (default 3), -t timeout ms (default 500), -B backoff (default 1.5).
fping -g 192.168.96.0/27 -a -r 1 -t 200fping < /tmp/hosts.txt -r 1 -t 200fping -e 192.168.96.10 192.168.96.20fping -s -q -r 0 -t 200 -g 192.168.96.0/28$ fping -g 192.168.96.0/27 -a -r 1 -t 200192.168.96.1192.168.96.5192.168.96.10192.168.96.20192.168.96.30$ fping < /tmp/hosts.txt -r 1 -t 200192.168.96.10 is alive192.168.96.20 is alive192.168.96.40 is unreachable$ fping -e 192.168.96.10 192.168.96.20192.168.96.10 is alive (0.258 ms)192.168.96.20 is alive (0.129 ms)$ fping -s -q -r 0 -t 200 -g 192.168.96.0/28 14 targets 3 alive 11 unreachable 14 ICMP Echos sent 3 ICMP Echo Replies received 0.109 ms (avg round trip time) 0.334 sec (elapsed real time)76.7 fping: count, timing and MTU test
- -c 3 sends 3 pings per target with loss and min/avg/max; -C 3 prints all RTTs on one line (- = lost).
- -D adds a Unix timestamp, -p is the gap between pings to the same host, -i the minimum gap between any two packets.
- -b sets data size, -M sets Don't Fragment: 1472 bytes + 28 header = 1500 passes, 1473 is lost.
- -H sets TTL, -I eth0 binds to an interface (SO_BINDTODEVICE, needs sudo), -o reports outage time, -l loops.
fping -C 3 -q 192.168.96.10 192.168.96.20 192.168.96.40fping -b 1472 -M -c 1 192.168.96.10fping -b 1473 -M -c 1 192.168.96.10$ fping -C 3 -q 192.168.96.10 192.168.96.20 192.168.96.40192.168.96.10 : 0.163 0.103 0.131192.168.96.20 : 0.176 0.124 0.112192.168.96.40 : - - -$ fping -b 1472 -M -c 1 192.168.96.10192.168.96.10 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 0.120/0.120/0.120192.168.96.10 : [0], 1480 bytes, 0.120 ms (0.120 avg, 0% loss)$ fping -b 1473 -M -c 1 192.168.96.10192.168.96.10 : xmt/rcv/%loss = 1/0/100%76.8 arp-scan
- Needs root or CAP_NET_RAW. --localnet scans the interface's whole subnet (256 hosts in about 3 s).
- Docker MACs are locally administered, so the vendor (from the IEEE OUI file) is Unknown.
- -I picks the interface; targets as a range or --file.
- --quiet --plain gives only IP and MAC for scripts; --format and --rtt build custom lines.
- --random/--randomseed, --retry, --timeout, --interval, --resolve (-x = --plain); --arpspa=0.0.0.0 works on an interface without IPv4; --limit, --pcapsavefile, --vlan.
arp-scan --localnetarp-scan --quiet --plain 192.168.96.0/27arp-scan --arpspa=0.0.0.0 -x 192.168.96.8-192.168.96.30$ arp-scan --localnetInterface: eth0, type: EN10MB, MAC: ee:8e:49:f1:e6:55, IPv4: 192.168.96.5Starting arp-scan 1.10.0 with 256 hosts192.168.96.1 da:0e:47:a7:e0:78 (Unknown: locally administered)192.168.96.10 e2:cb:64:e7:0a:ed (Unknown: locally administered)192.168.96.20 8e:c9:2d:27:0e:d9 (Unknown: locally administered)192.168.96.30 b6:32:d5:86:69:aa (Unknown: locally administered)Ending arp-scan 1.10.0: 256 hosts scanned in 2.780 seconds (92.09 hosts/sec). 4 responded$ arp-scan --quiet --plain 192.168.96.0/27192.168.96.1 da:0e:47:a7:e0:78192.168.96.10 e2:cb:64:e7:0a:ed192.168.96.20 8e:c9:2d:27:0e:d9192.168.96.30 b6:32:d5:86:69:aa$ arp-scan --arpspa=0.0.0.0 -x 192.168.96.8-192.168.96.30192.168.96.10 e2:cb:64:e7:0a:ed (Unknown: locally administered)192.168.96.20 8e:c9:2d:27:0e:d9 (Unknown: locally administered)192.168.96.30 b6:32:d5:86:69:aa (Unknown: locally administered)76.9 Comparison: masscan vs fping vs arp-scan
| Point | masscan | fping | arp-scan |
|---|---|---|---|
| Finds | Open ports | Alive hosts (ICMP) | Alive hosts + MAC (ARP) |
| Scope | Any routable range | Any routable range | Same LAN only |
| Blocked by firewall | Port filtered | ICMP drop hides hosts | No: every IPv4 host answers ARP |
| Needs root | Yes (raw) | No (usually) | Yes / CAP_NET_RAW |
| Key flags | -p, --rate, --banners, -oL | -a -g, -c/-C, -b -M | --localnet, --plain, --format |
76.10 Common mistakes
- Treating masscan as an nmap replacement: it only says 'open' and can miss replies at high rates; follow up with nmap -sV on those hosts.
- Cranking --rate on a shared network and overloading it.
- Running shards without the same --seed: targets overlap.
- Using --banners without a spare --adapter-ip: the kernel RSTs the connection.
- Trusting fping alone when laptops block ICMP: use arp-scan on the LAN.
76.11 Interview tips
- masscan is fast because it is stateless: its own TCP stack, no connection table, a separate receive thread, and a SYN cookie in the sequence number to verify replies.
- Ping blocked on your own LAN? Use arp-scan: every IPv4 host must answer ARP.
- Workflow: masscan for open ports -> nmap -sV/-A only on the hits.
- MTU check with fping -b 1472 -M (1472 + 28 = 1500).