Skip to content

Instantly share code, notes, and snippets.

Last active July 21, 2020 00:08
What would you like to do?
This script listens for ARP request packets using scapy to learn the IP and Mac Address of LAN hosts. Learn more about this script at
#!/usr/bin/env python3
Listen for arp packets using scapy to learn the IP and Mac Address of LAN hosts
Copyright (C) 2018 Jonathan Cutrer
License Dual MIT, 0BSD
from __future__ import print_function
from scapy.all import *
import time
__version__ = "0.0.1"
def handle_arp_packet(packet):
# Match ARP requests
if packet[ARP].op == ARP.who_has:
print('New ARP Request')
print(packet[Ether].src, "has IP", packet[ARP].psrc)
# Match ARP replies
if packet[ARP].op == ARP.is_at:
print('New ARP Reply')
if __name__ == "__main__":
sniff(filter="arp", prn=handle_arp_packet)
Copy link

franciscopaglia commented Jul 21, 2020

Nice! Thank you! I had to make a small tweak and define the corresponding values for the OpCode field in the ARP packet:

who_has = 1;
is_at = 2;

# ...

if packet[ARP].op == who_has
if packet[ARP].op == is_at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment