Using MAC Addresses for Network Inventory, the Right Way

Lookup & troubleshooting

A MAC address looks like an ideal asset identifier: globally unique, independent of IP changes, and collectable without installing an agent anywhere. Using it as a primary key, however, creates problems a few years down the line. Here is what role it should actually play.

What it is good for

Agentless collection. Switch MAC address tables, DHCP leases and ARP tables give you a network-wide device list without logging into a single machine.

Inferring device type. The first 24 bits identify the vendor, so a lookup gives you a rough classification. A printer vendor, a camera vendor or a virtualisation prefix tells you most of what you need. For bulk identification, use the JSON endpoint behind the lookup page:

curl "https://7n4.cn/api/mac2vendor?mac=40:6c:8f:18:2c:03"

Finding unregistered devices. Compare scanned addresses against the register, and the difference is your list to investigate. It is one of the most effective ways to surface shadow devices.

Where it falls short

Mobile addresses are unstable. Address randomisation gives phones, tablets and laptops a different address per network, and some platforms rotate periodically. Counting devices by MAC overstates the total substantially.

One device has several addresses. Wired port, wireless, Bluetooth and out-of-band management each have one, and a virtualisation host adds a pile of virtual interfaces. Tying them to a single asset needs additional information.

Replacing an adapter changes the identity. After a board repair or a card swap the same physical device has a new MAC, leaving a ghost record in the register.

The vendor is not the brand. IEEE records identify the registrant, and prefixes belonging to contract manufacturers and module suppliers are common, as explained in why a lookup returns nothing or the wrong vendor.

The recommended approach

Key on an asset number and treat MAC as an attribute. Specifically, a multi-valued attribute. Record every interface MAC for a device, and let any of them resolve to that asset. When an adapter is replaced, add the new value and mark the old one historical rather than overwriting it.

Separate stable assets from mobile devices. Servers, network gear, printers, cameras and industrial controllers do not randomise, so their MACs are reliable identifiers worth maintaining precisely. Give up MAC-based tracking for personal mobile devices and anchor on 802.1X user identity instead, as discussed in 802.1X and MAC authentication bypass.

Add location from LLDP and CDP. Neighbour discovery tells you which switch and which port a device is attached to, which is operationally more valuable than the MAC itself:

show lldp neighbors detail

Record the source and timestamp. One MAC may appear in a switch table, a DHCP lease and a scan result at once. Keeping the origin and collection time of each data point is what lets you tell a genuinely online device from a stale leftover.

Classify automatically by prefix. Virtualisation prefixes are regular enough to drive rules that split physical from virtual assets; the table is in MAC addresses in virtual machines and containers. Locally administered addresses, where the second hex character is 2, 6, A or E, should go straight into a "random or virtual" bucket rather than being tracked.

A simple collection script

#!/bin/bash
# scan the local segment and annotate with vendor
sudo arp-scan --localnet --plain | while read ip mac rest; do
  vendor=$(curl -s "https://7n4.cn/api/mac2vendor?mac=$mac" \
           | python3 -c 'import sys,json; print(json.load(sys.stdin).get("comment","unknown"))' 2>/dev/null)
  printf "%-16s %-18s %s\n" "$ip" "$mac" "$vendor"
done

The output can be diffed against the register directly. Note that the endpoint has abuse protections, so keep the rate moderate on large runs or cache the prefix-to-vendor mapping locally.

Review on a schedule

A register is only worth having if it is accurate. A network-wide scan once a quarter, compared against the records, is a reasonable cadence. Three kinds of discrepancy deserve attention: devices scanned but absent from the register, devices registered but long absent from the network, and devices whose vendor does not match their recorded type. The third category often reveals hardware that was swapped or an asset recorded incorrectly.

Related Articles
About the Author · Jondy

Network engineer with a background in enterprise network operations and security. Founded 7n4.cn in 2017. Questions or suggestions are welcome—get in touch.

← Back to Blog