summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-07-24 02:35:14 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-07-24 05:44:19 +0700
commite92c9cd923fe6d4cdce073ffe397ede2b09b30c3 (patch)
tree1a8b9aaac2ed31437d0f09b9e953a1d678c0e6aa /src
parent7cde195e30b2259d176b7c913ddda4685592d6a8 (diff)
trx_toolkit/trx_sniff.py: add support for reading from PCAP file
Diffstat (limited to 'src')
-rwxr-xr-xsrc/target/trx_toolkit/trx_sniff.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/target/trx_toolkit/trx_sniff.py b/src/target/trx_toolkit/trx_sniff.py
index 6592455a..45a5cf4b 100755
--- a/src/target/trx_toolkit/trx_sniff.py
+++ b/src/target/trx_toolkit/trx_sniff.py
@@ -61,18 +61,29 @@ class Application(ApplicationBase):
pkt_filter = "udp and (port %d or port %d)" \
% (self.argv.base_port + 2, self.argv.base_port + 102)
- log.info("Listening on interface '%s'..." % self.argv.sniff_if)
+ # Arguments to be passed to scapy.all.sniff()
+ sniff_args = {
+ "prn" : self.pkt_handler,
+ "filter" : pkt_filter,
+ "store" : 0,
+ }
+
+ if self.argv.cap_file is not None:
+ log.info("Reading packets from '%s'..." % self.argv.cap_file)
+ sniff_args["offline"] = self.argv.cap_file
+ else:
+ log.info("Listening on interface '%s'..." % self.argv.sniff_if)
+ sniff_args["iface"] = self.argv.sniff_if
# Start sniffing...
- scapy.all.sniff(iface = self.argv.sniff_if, store = 0,
- filter = pkt_filter, prn = self.pkt_handler)
+ scapy.all.sniff(**sniff_args)
# Scapy registers its own signal handler
self.shutdown()
def pkt_handler(self, ether):
# Prevent loopback packet duplication
- if self.argv.sniff_if == "lo":
+ if self.argv.sniff_if == "lo" and self.argv.cap_file is None:
self.lo_trigger = not self.lo_trigger
if not self.lo_trigger:
return
@@ -197,9 +208,6 @@ class Application(ApplicationBase):
self.app_reg_logging_options(parser)
trx_group = parser.add_argument_group("TRX interface")
- trx_group.add_argument("-i", "--sniff-interface",
- dest = "sniff_if", type = str, default = "lo", metavar = "IF",
- help = "Set network interface (default '%(default)s')")
trx_group.add_argument("-p", "--base-port",
dest = "base_port", type = int, default = 6700,
help = "Set base port number (default %(default)s)")
@@ -207,6 +215,14 @@ class Application(ApplicationBase):
dest = "output_file", type = str,
help = "Write bursts to a capture file")
+ input_group = trx_group.add_mutually_exclusive_group()
+ input_group.add_argument("-i", "--sniff-interface",
+ dest = "sniff_if", type = str, default = "lo", metavar = "IF",
+ help = "Set network interface (default '%(default)s')")
+ input_group.add_argument("-r", "--capture-file",
+ dest = "cap_file", type = str, metavar = "FILE",
+ help = "Read packets from a PCAP file")
+
cnt_group = parser.add_argument_group("Count limitations (optional)")
cnt_group.add_argument("--frame-count", metavar = "N",
dest = "frame_count", type = int,