• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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):
10    """Generate IPv6 Router Advertisement and send to destination.
11
12    @param dstmac: string HWAddr of the destination ipv6 node.
13    @param interval: int Time to sleep between consecutive packets.
14    @param count: int Number of packets to be sent.
15    @param lifetime: Router lifetime value for the original RA.
16    @param iface: string Router's WiFi interface to send packets over.
17
18    """
19    while count:
20        ra = (scapy.Ether(dst=dstmac) /
21              scapy.IPv6() /
22              scapy.ICMPv6ND_RA(routerlifetime=lifetime))
23        scapy.sendp(ra, iface=iface)
24        count = count - 1
25        time.sleep(interval)
26        lifetime = lifetime - interval
27
28
29if __name__ == "__main__":
30    parser = argparse.ArgumentParser()
31    parser.add_argument('-m', '--mac-address', action='store', default=None,
32                         help='HWAddr to send the packet to.')
33    parser.add_argument('-i', '--t-interval', action='store', default=None,
34                         type=int, help='Time to sleep between consecutive')
35    parser.add_argument('-c', '--pkt-count', action='store', default=None,
36                        type=int, help='NUmber of packets to send.')
37    parser.add_argument('-l', '--life-time', action='store', default=None,
38                        type=int, help='Lifetime in seconds for the first RA')
39    parser.add_argument('-in', '--wifi-interface', action='store', default=None,
40                        help='The wifi interface to send packets over.')
41    args = parser.parse_args()
42    send(args.mac_address, args.t_interval, args.pkt_count, args.life_time,
43         args.wifi_interface)
44