1#!/usr/local/bin/python3 2# send Address Resolution Protocol Probe 3# expect Address Resolution Protocol response and check all fields 4# RFC 5227 IPv4 Address Conflict Detection 5# 2.1.1. Probe Details 6 7 8import os 9from addr import * 10from scapy.all import * 11 12arp=ARP(op='who-has', hwsrc=LOCAL_MAC, psrc="0.0.0.0", 13 hwdst="00:00:00:00:00:00", pdst=REMOTE_ADDR) 14eth=Ether(src=LOCAL_MAC, dst="ff:ff:ff:ff:ff:ff")/arp 15 16e=srp1(eth, iface=LOCAL_IF, timeout=2) 17 18if e and e.type == ETH_P_ARP: 19 a=e.payload 20 if a.hwtype != ARPHDR_ETHER: 21 print("HWTYPE=%#0.4x != ARPHDR_ETHER" % (a.hwtype)) 22 exit(1) 23 if a.ptype != ETH_P_IP: 24 print("PTYPE=%#0.4x != ETH_P_IP" % (a.ptype)) 25 exit(1) 26 if a.hwlen != 6: 27 print("HWLEN=%d != 6" % (a.hwlen)) 28 exit(1) 29 if a.plen != 4: 30 print("PLEN=%d != 4" % (a.plen)) 31 exit(1) 32 if a.op != 2: 33 print("OP=%s != is-at" % (a.op)) 34 exit(1) 35 if a.hwsrc != REMOTE_MAC: 36 print("HWLOCAL=%s != REMOTE_MAC" % (a.hwsrc)) 37 exit(1) 38 if a.psrc != REMOTE_ADDR: 39 print("PLOCAL=%s != REMOTE_ADDR" % (a.psrc)) 40 exit(1) 41 if a.hwdst != LOCAL_MAC: 42 print("HWREMOTE=%s != LOCAL_MAC" % (a.hwdst)) 43 exit(1) 44 if a.pdst != "0.0.0.0": 45 print("PREMOTE=%s != 0.0.0.0" % (a.pdst)) 46 exit(1) 47 print("arp reply") 48 exit(0) 49 50print("NO ARP REPLY") 51exit(2) 52