1#!/usr/local/bin/python3 2# send Unsolicited Neighbor Advertisement 3 4print("send unsolicited neighbor advertisement packet") 5 6import os 7from addr import * 8from scapy.all import * 9 10# link-local solicited-node multicast address 11def nsma(a): 12 n = inet_pton(socket.AF_INET6, a) 13 return inet_ntop(socket.AF_INET6, in6_getnsma(n)) 14 15# ethernet multicast address of multicast address 16def nsmac(a): 17 n = inet_pton(socket.AF_INET6, a) 18 return in6_getnsmac(n) 19 20# ethernet multicast address of solicited-node multicast address 21def nsmamac(a): 22 return nsmac(nsma(a)) 23 24# link-local address 25def lla(m): 26 return "fe80::"+in6_mactoifaceid(m) 27 28ip=IPv6(src=lla(LOCAL_MAC), dst="ff02::1")/ICMPv6ND_NA(tgt=LOCAL_ADDR6) 29eth=Ether(src=LOCAL_MAC, dst=nsmac("ff02::1"))/ip 30 31sendp(eth, iface=LOCAL_IF) 32time.sleep(1) 33 34exit(0) 35