Build a Python ARP Scanner for Your Home Network (Full Code Included)
Your router’s admin page lists connected devices, but it is slow, clunky, and sometimes incomplete. Let us build something better: a Python ARP scanner that sweeps your home network and prints every device it finds, with IP address, MAC address, and a guess at the vendor. It runs on your own network only — scanning someone else’s network without permission is not okay.
How ARP scanning works
Every device on a local network answers ARP requests — “who has this IP address?” — with its MAC address. Send one ARP request to every address in your subnet, collect the replies, and you have a device list. No port scanning, no login attempts, just the protocol networks use to function.
The code
You need Scapy, Python’s packet-crafting library.
pip install scapy
Then save this as arp_scan.py.
from scapy.all import ARP, Ether, srpdef scan(network): arp = ARP(pdst=network) ether = Ether(dst="ff:ff:ff:ff:ff:ff") packet = ether / arp answered, _ = srp(packet, timeout=2, verbose=False) devices = [] for _, reply in answered: devices.append({"ip": reply.psrc, "mac": reply.hwsrc}) return devicesif __name__ == "__main__": target = input("Network to scan (e.g. 192.168.1.0/24): ") devices = scan(target) print(f"Scanning {target}...") print(f"{'IP Address':<18}{'MAC Address'}") print("-" * 40) for device in devices: print(f"{device['ip']:<18}{device['mac']}") print(f"Found {len(devices)} device(s).")
Running it
sudo python3 arp_scan.py
Root is needed because Scapy crafts raw packets. Enter your subnet — usually something like 192.168.1.0/24 — and within a couple of seconds you get every responding device. Compare the list against what you expect: your phone, laptop, TV, router. An unknown MAC address is worth investigating — it could be a forgotten smart device, or a neighbour on your Wi-Fi.
How it works, line by line
- ARP(pdst=network) builds a request asking “who has each address in this range?”
- Ether(dst=”ff:ff:ff:ff:ff:ff”) wraps it in a broadcast frame so every device on the LAN sees it.
- srp() sends the packet and collects replies, with a 2-second timeout.
- Each reply carries the responder’s IP (psrc) and MAC address (hwsrc).
Level up
- Add vendor lookup: the first half of a MAC address identifies the manufacturer, and libraries like manuf can resolve it offline.
- Save results to a file and diff them daily — a new device appearing overnight is an early warning worth having.
- Turn it into a scheduled check with cron that emails you when an unknown MAC appears.
You just built a network visibility tool. Defenders cannot protect devices they cannot see — and now you can see yours.



Comments
Post a Comment