1#!/usr/bin/python 2 3import argparse 4import time 5 6from scapy import all as scapy 7 8 9def send(dstmac, interval, count, lifetime, iface, rtt): 10 """Generate IPv6 Router Advertisement and send to destination. 11 12 Args: 13 1. dstmac: string HWAddr of the destination ipv6 node. 14 2. interval: int Time to sleep between consecutive packets. 15 3. count: int Number of packets to be sent. 16 4. lifetime: Router lifetime value for the original RA. 17 5. iface: string Router's WiFi interface to send packets over. 18 6. rtt: retrans timer in the RA packet 19 20 """ 21 while count: 22 ra = (scapy.Ether(dst=dstmac) / 23 scapy.IPv6() / 24 scapy.ICMPv6ND_RA(routerlifetime=lifetime, retranstimer=rtt)) 25 scapy.sendp(ra, iface=iface) 26 count = count - 1 27 time.sleep(interval) 28 lifetime = lifetime - interval 29 30 31if __name__ == "__main__": 32 parser = argparse.ArgumentParser() 33 parser.add_argument('-m', '--mac-address', action='store', default=None, 34 help='HWAddr to send the packet to.') 35 parser.add_argument('-i', '--t-interval', action='store', default=None, 36 type=int, help='Time to sleep between consecutive') 37 parser.add_argument('-c', '--pkt-count', action='store', default=None, 38 type=int, help='NUmber of packets to send.') 39 parser.add_argument('-l', '--life-time', action='store', default=None, 40 type=int, help='Lifetime in seconds for the first RA') 41 parser.add_argument('-in', '--wifi-interface', action='store', default=None, 42 help='The wifi interface to send packets over.') 43 parser.add_argument('-rtt', '--retrans-timer', action='store', default=None, 44 type=int, help='Retrans timer') 45 args = parser.parse_args() 46 send(args.mac_address, args.t_interval, args.pkt_count, args.life_time, 47 args.wifi_interface, args.retrans_timer) 48