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