]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/lib/scapy_sendpkt.py
2 # -*- coding: utf-8 eval: (blacken-mode 1) -*-
3 # SPDX-License-Identifier: MIT
5 # July 29 2021, Christian Hopps <chopps@labn.net>
7 # Copyright (c) 2021, LabN Consulting, L.L.C. ("LabN")
14 from scapy
.all
import conf
, srp
20 parser
= argparse
.ArgumentParser()
21 parser
.add_argument("-i", "--interface", help="interface to send packet on.")
22 parser
.add_argument("-I", "--imports", help="scapy symbols to import")
24 "-t", "--timeout", type=float, default
=2.0, help="timeout for reply receipts"
26 parser
.add_argument("pktdef", help="scapy packet definition to send")
27 args
= parser
.parse_args()
30 i
= args
.imports
.replace("\n", "").strip()
31 if not re
.match("[a-zA-Z0-9_ \t,]", i
):
32 logging
.critical('Invalid imports specified: "%s"', i
)
34 exec("from scapy.all import " + i
, globals(), locals())
36 ans
, unans
= srp(eval(args
.pktdef
), iface
=args
.interface
, timeout
=args
.timeout
)
40 print(pkt
.answer
.show(dump
=True))
43 if __name__
== "__main__":