1*a8307021Sbluhm#!/usr/local/bin/python3 228050b02Sbluhm# send Neighbor Unreachability Detection neighbor solicitation 328050b02Sbluhm# expect an neighbor advertisement answer and check it 428050b02Sbluhm 5*a8307021Sbluhmprint("send neighbor unreachability detection solicitation packet") 67b3475a7Sbluhm 728050b02Sbluhmimport os 828050b02Sbluhmfrom addr import * 928050b02Sbluhmfrom scapy.all import * 1028050b02Sbluhm 1128050b02Sbluhm# link-local solicited-node multicast address 1228050b02Sbluhmdef nsma(a): 1328050b02Sbluhm n = inet_pton(socket.AF_INET6, a) 1428050b02Sbluhm return inet_ntop(socket.AF_INET6, in6_getnsma(n)) 1528050b02Sbluhm 1628050b02Sbluhm# ethernet multicast address of multicast address 1728050b02Sbluhmdef nsmac(a): 1828050b02Sbluhm n = inet_pton(socket.AF_INET6, a) 1928050b02Sbluhm return in6_getnsmac(n) 2028050b02Sbluhm 2128050b02Sbluhm# ethernet multicast address of solicited-node multicast address 2228050b02Sbluhmdef nsmamac(a): 2328050b02Sbluhm return nsmac(nsma(a)) 2428050b02Sbluhm 2528050b02Sbluhm# link-local address 2628050b02Sbluhmdef lla(m): 2728050b02Sbluhm return "fe80::"+in6_mactoifaceid(m) 2828050b02Sbluhm 297b3475a7Sbluhmip=IPv6(src=LOCAL_ADDR6, dst=REMOTE_ADDR6)/ICMPv6ND_NS(tgt=REMOTE_ADDR6) 307b3475a7Sbluhmeth=Ether(src=LOCAL_MAC, dst=REMOTE_MAC)/ip 3128050b02Sbluhm 3228050b02Sbluhmif os.fork() == 0: 3328050b02Sbluhm time.sleep(1) 347b3475a7Sbluhm sendp(eth, iface=LOCAL_IF) 3528050b02Sbluhm os._exit(0) 3628050b02Sbluhm 377b3475a7Sbluhmans=sniff(iface=LOCAL_IF, timeout=3, filter= 387b3475a7Sbluhm "ip6 and src "+REMOTE_ADDR6+" and dst "+LOCAL_ADDR6+" and icmp6") 3928050b02Sbluhmfor a in ans: 409c70e3bfSbluhm if a and a.type == ETH_P_IPV6 and \ 4128050b02Sbluhm ipv6nh[a.payload.nh] == 'ICMPv6' and \ 4228050b02Sbluhm icmp6types[a.payload.payload.type] == 'Neighbor Advertisement': 4328050b02Sbluhm tgt=a.payload.payload.tgt 44*a8307021Sbluhm print("target=%s" % (tgt)) 457b3475a7Sbluhm if tgt == REMOTE_ADDR6: 4628050b02Sbluhm exit(0) 47*a8307021Sbluhm print("TARGET!=%s" % (REMOTE_ADDR6)) 4828050b02Sbluhm exit(1) 49*a8307021Sbluhmprint("NO NEIGHBOR ADVERTISEMENT") 5028050b02Sbluhmexit(2) 51