Skip to content

Instantly share code, notes, and snippets.

@rostegg
Created March 16, 2019 22:41
Show Gist options
  • Select an option

  • Save rostegg/8efb20896aa67f47dea10a0ca7b074a1 to your computer and use it in GitHub Desktop.

Select an option

Save rostegg/8efb20896aa67f47dea10a0ca7b074a1 to your computer and use it in GitHub Desktop.
Simple detecting of ARP spoofing
from scapy.all import sniff, ARP
import sys
arp_table = {}
def watch_arp(packet):
if packet[ARP].op == 2:
if arp_table.get(packet[ARP].psrc) == None:
print ("Register new device %s:%s"%(packet[ARP].hwsrc,packet[ARP].psrc))
arp_table[packet[ARP].psrc] = packet[ARP].hwsrc
elif arp_table.get(packet[ARP].psrc) and arp_table[packet[ARP].psrc] != packet[ARP].hwsrc:
print("Detected spoofing, %s change his IP from %s to %s"%(packet[ARP].hwsrc, arp_table[packet[ARP].psrc],packet[ARP].psrc))
arp_table[packet[ARP].psrc] = packet[ARP].hwsrc
print("Starting monitor..")
# for choosing interface to sniff set: iface="iface_name"
sniff(prn=watch_arp,filter="arp",store=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment