arpDetector.py 612 B

123456789101112131415161718192021222324
  1. from scapy.all import sniff
  2. ip_mac_map = {}
  3. def process(packet):
  4. src_ip = packet['ARP'].psrc
  5. src_mac = packet['Ether'].src
  6. if src_mac in ip_mac_map.keys():
  7. if ip_mac_map[src_mac] != src_ip:
  8. try:
  9. old_ip = ip_mac_map[src_mac]
  10. except:
  11. old_ip = "unknown"
  12. message = (f"Possible ARP attack detected. It is possible that the machine with IP address {str(old_ip)} is pretending to be {str(src_ip)}")
  13. return message
  14. else:
  15. ip_mac_map[src_mac] = src_ip
  16. sniff(count=0, filter="arp", store=0, prn=process)