Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 36 ยท Host Discovery

ARP and Local Network Discovery

Learn how ARP works, why Nmap uses it on local networks, how MAC addresses and vendor prefixes are reported, and how to build and read an ARP packet in Python.

On the same local network, there is a discovery method that is faster and more reliable than any ping: ARP, the Address Resolution Protocol. Almost every device on an Ethernet or Wi-Fi network must answer ARP, because it cannot communicate at all without it. That is why Nmap switches to ARP automatically when the target is on your local segment and you have raw-packet privileges.

This lesson explains ARP, what Nmap shows when it uses it (MAC address, vendor), the options that control it, and builds a real ARP packet in bytes so you see what is on the wire.

ARP works only inside one broadcast domain (one switch/VLAN/Wi-Fi network); it never crosses a router. Commands are read-only. The Python editors build and decode packets as bytes in memory; nothing is sent.

Why ARP exists

IP addresses are logical; the network hardware delivers frames using MAC addresses, 48-bit identifiers such as 00:11:22:aa:bb:0a. To send a packet to 192.0.2.10, your computer needs that machine's MAC. It broadcasts a question to everyone on the segment:

sequenceDiagram
  participant A as Scanner 192.0.2.5
  participant All as Whole LAN (broadcast)
  participant B as Host 192.0.2.10
  A->>All: ARP request: who has 192.0.2.10? tell 192.0.2.5
  B->>A: ARP reply: 192.0.2.10 is at 00:11:22:aa:bb:0a

Figure: an ARP request is broadcast; only the owner of the address answers.

A host with a firewall can drop ICMP and TCP, but the operating system still answers ARP, or it would be unreachable by its neighbors. So an ARP-based sweep finds hosts that ignore pings.

Using ARP discovery in Nmap

As root on a local network, nmap -sn uses ARP by default. You can force it or turn it off:

Terminal
sudo nmap -sn -PR 192.0.2.0/24        # explicit ARP discovery (-PR)
sudo nmap -sn --send-ip 192.0.2.0/24  # do NOT use ARP; use IP-level probes instead
sudo nmap -PR -sn -n -oG - 192.0.2.0/24

Example output with vendor lookup:

TEXT
Nmap scan report for 192.0.2.1
Host is up (0.00045s latency).
MAC Address: 00:11:22:AA:BB:01 (Example Router Co.)
Nmap scan report for 192.0.2.23
Host is up (0.0021s latency).
MAC Address: 00:11:22:AA:BB:17 (Example Phone Maker)
Nmap done: 256 IP addresses (2 hosts up) scanned in 1.9 seconds

Example output (invented MACs and vendors). The vendor name comes from the OUI, the first three bytes of the MAC, which the IEEE assigns to each manufacturer. Nmap ships a lookup file (nmap-mac-prefixes). The same device can use a random MAC on modern phones ("private Wi-Fi address"), so the vendor may then be unknown or misleading.

Two more facts:

  • ARP discovery needs root (or Administrator + Npcap). Without privileges Nmap falls back to TCP connect probes.
  • Because ARP replies come from the OS, reason shows arp-response. A host that is up but filtered at IP level still shows as up with this reason.

Seeing the ARP cache without scanning

Your own computer remembers recent ARP answers. You can look at that table with no traffic at all:

Terminal
arp -a          # Windows, macOS, many Linux
ip neigh        # modern Linux

It lists IP-to-MAC pairs for devices your machine has recently talked to, a free peek at local neighbors.

ARP and security

ARP has no authentication. Any device can claim "I am 192.0.2.1", which is the basis of ARP spoofing (man-in-the-middle on a LAN). Defenders watch for it with tools such as switch features (Dynamic ARP Inspection) and monitors that alert when a MAC address changes for a known IP. Nmap's job is to observe the neighborhood; you should know what a healthy table looks like so that changes stand out. See Reporting and Automation for comparing scans over time.

A stand-in: build an ARP request in bytes

An Ethernet frame carrying an ARP request is only 42 bytes. This program builds one with struct and prints it in hex, labelling the fields. It sends nothing.

Python Build an ARP request frame

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.

The destination MAC is all ff, which every device on the segment accepts; the target MAC inside the ARP body is all zeros because that is exactly what we are asking about.

A stand-in: decode an ARP reply and look up a vendor

Now the other direction: read a captured reply and map the MAC prefix to a vendor from a tiny invented table.

Python Decode an ARP reply

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.

The last line checks bit 0x02 of the first byte, which marks a locally administered address. Devices that randomize their MAC for privacy set this bit, so a vendor lookup is meaningless for them.

When ARP discovery is not available

  • The target is on a different subnet (reached through a router): use ICMP and TCP probes, see Discovery Probes: TCP, UDP and ICMP.
  • You are running as an unprivileged user: Nmap cannot craft ARP frames.
  • You are scanning through a VPN or tunnel with no link-layer: only IP probes work.
  • Some Wi-Fi networks use client isolation, which blocks traffic between devices (and often ARP answers from peers).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is ARP discovery so reliable on a local network?

    Without answering ARP a host would be unreachable from its neighbors, so firewalls rarely block it.
  2. 2. What part of a MAC address identifies the manufacturer?

    The first three bytes are the Organizationally Unique Identifier assigned by the IEEE.
  3. 3. Can Nmap use ARP to find a host on a different subnet?

    ARP is not routed, so across subnets Nmap must use IP-level probes.
  4. 4. What does the first byte's 0x02 bit tell you about a MAC address?

    The locally-administered bit marks addresses not assigned by a vendor, such as privacy MACs.

Summary

  • ARP maps IP addresses to MAC addresses on one network segment and is the default discovery method there (as root).
  • Nmap reports the MAC and a vendor guess from the OUI; randomized MACs defeat the guess.
  • ARP does not cross routers and needs raw-packet privileges.
  • ARP is unauthenticated, which allows spoofing; watching the neighbor table helps defenders.
  • Bytes in, bytes out: an ARP frame is just a few fields you can build and decode yourself.

Next: Discovery Probes: TCP, UDP and ICMP