1#!/usr/local/bin/python2.7 2# send a ping6 packet without routing header type 0 3# we expect an echo reply, as there is no routing header 4 5import os 6from addr import * 7from scapy.all import * 8 9pid=os.getpid() 10payload="ABCDEFGHIJKLMNOP" 11packet=IPv6(src=SRC_OUT6, dst=DST_IN6)/\ 12 ICMPv6EchoRequest(id=pid, data=payload) 13eth=Ether(src=SRC_MAC, dst=DST_MAC)/packet 14 15if os.fork() == 0: 16 time.sleep(1) 17 sendp(eth, iface=SRC_IF) 18 os._exit(0) 19 20ans=sniff(iface=SRC_IF, timeout=3, filter= 21 "ip6 and dst "+SRC_OUT6+" and icmp6") 22for a in ans: 23 if a and a.type == ETH_P_IPV6 and \ 24 ipv6nh[a.payload.nh] == 'ICMPv6' and \ 25 icmp6types[a.payload.payload.type] == 'Echo Reply': 26 reply=a.payload.payload 27 id=reply.id 28 print "id=%#x" % (id) 29 if id != pid: 30 print "WRONG ECHO REPLY ID" 31 exit(2) 32 data=reply.data 33 print "payload=%s" % (data) 34 if data != payload: 35 print "WRONG PAYLOAD" 36 exit(2) 37 exit(0) 38print "NO ICMP6 ECHO REPLY" 39exit(1) 40