1#- 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2024 Klara, Inc. 5# 6 7import argparse 8import scapy.all as sp 9import sys 10 11# 12# Emit a router advertisement with the specified prefix. 13# 14def main(): 15 parser = argparse.ArgumentParser("ra.py", 16 description="Emits Router Advertisement packets") 17 parser.add_argument('--sendif', nargs=1, required=True, 18 help='The interface through which the packet will be sent') 19 parser.add_argument('--src', nargs=1, required=True, 20 help='The source IP address') 21 parser.add_argument('--dst', nargs=1, required=True, 22 help='The destination IP address') 23 parser.add_argument('--prefix', nargs=1, required=True, 24 help='The prefix to be advertised') 25 parser.add_argument('--prefixlen', nargs=1, required=True, type=int, 26 help='The prefix length to be advertised') 27 28 args = parser.parse_args() 29 pkt = sp.Ether() / \ 30 sp.IPv6(src=args.src, dst=args.dst) / \ 31 sp.ICMPv6ND_RA(chlim=64) / \ 32 sp.ICMPv6NDOptPrefixInfo(prefix=args.prefix, prefixlen=args.prefixlen) 33 34 sp.sendp(pkt, iface=args.sendif[0], verbose=False) 35 sys.exit(0) 36 37if __name__ == '__main__': 38 main() 39