]>
Commit | Line | Data |
---|---|---|
f40b18e8 KK |
1 | # |
2 | # Copyright (c) 2019 by VMware, Inc. ("VMware") | |
3 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. | |
4 | # ("NetDEF") in this file. | |
5 | # | |
6 | # Permission to use, copy, modify, and/or distribute this software | |
7 | # for any purpose with or without fee is hereby granted, provided | |
8 | # that the above copyright notice and this permission notice appear | |
9 | # in all copies. | |
10 | # | |
11 | # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES | |
12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR | |
14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY | |
15 | # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
16 | # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |
17 | # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
18 | # OF THIS SOFTWARE. | |
19 | # | |
20 | ||
21 | import sys | |
22 | import argparse | |
23 | from scapy.all import Raw, sendp | |
24 | import binascii | |
25 | ||
26 | ||
27 | def send_packet(packet, iface, interval, count): | |
28 | """ | |
29 | Read BSR packet in Raw format and send it to specified interface | |
30 | ||
31 | Parameter: | |
32 | --------- | |
33 | * `packet` : BSR packet in raw format | |
34 | * `interface` : Interface from which packet would be send | |
35 | * `interval` : Interval between the packets | |
36 | * `count` : Number of packets to be sent | |
37 | """ | |
38 | ||
39 | data = binascii.a2b_hex(packet) | |
40 | p = Raw(load=data) | |
41 | p.show() | |
42 | sendp(p, inter=int(interval), iface=iface, count=int(count)) | |
43 | ||
44 | ||
45 | if __name__ == "__main__": | |
46 | parser = argparse.ArgumentParser(description="Send BSR Raw packet") | |
47 | parser.add_argument("packet", help="Packet in raw format") | |
48 | parser.add_argument("iface", help="Packet send to this ineterface") | |
49 | parser.add_argument("--interval", help="Interval between packets", default=0) | |
50 | parser.add_argument( | |
51 | "--count", help="Number of times packet is sent repetitively", default=0 | |
52 | ) | |
53 | args = parser.parse_args() | |
54 | ||
55 | if not args.packet or not args.iface: | |
56 | sys.exit(1) | |
57 | ||
58 | send_packet(args.packet, args.iface, args.interval, args.count) |