wireshark/tools/list_protos_in_cap.sh
Peter Wu 1ba4191c70 indexcap.py: fix tmpdir handling, python 3 compat
Add Python 3 compatibility to indexcap.py and only create a tmpdir for
actions that need it. Only remove tmpdir for the compare action and
try to remove the temp dir even if an exception occurs.

In list_protos_in_cap.sh, rename BIN_DIR to WS_BIN_PATH (matching
test/config.sh) and allow it to be overridden from the environment.

Tested with Python 2.6.6, 2.7.9, 3.2.6, 3.4.3 as follows (with tshark
built using cmake and '-b /tmp/wsbuild/run'):

    tools/indexcap.py out pop-ssl.pcapng;
    tools/indexcap.py out pop-ssl.pcapng --list-all-proto;
    tools/indexcap.py out pop-ssl.pcapng --list-all-files;
    tools/indexcap.py out pop-ssl.pcapng --list-all-proto-files=ssl;
    rm out;

Python 2.5.6 does not work (there is no multiprocessing module). The
dict output in Python 3.4.3 is different (has the hash function
changed?)

Change-Id: I592d8c4458a20d5088d815c6dd1cf90c9d3df9d3
Reviewed-on: https://code.wireshark.org/review/7792
Reviewed-by: Jeff Morriss <jeff.morriss.ws@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-03-25 07:09:41 +00:00

109 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
# List the protocols (dissectors) used in capture file(s)
#
# The Python script indexcap.py does the same thing.
#
# This script extracts the protocol names contained in a given capture file.
# This is useful for generating a "database" (flat file :-)) of in what file
# a given protocol can be found.
#
# Output consists of the file name followed by the protocols, for example:
# /path/to/the/file.pcap eth ip sctp
#
# Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Directory containing binaries. Default current directory.
WS_BIN_PATH=${WS_BIN_PATH:-.}
# Tweak the following to your liking. Editcap must support "-E".
TSHARK="$WS_BIN_PATH/tshark"
CAPINFOS="$WS_BIN_PATH/capinfos"
if [ "$WS_BIN_PATH" = "." ]; then
export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=
fi
NOTFOUND=0
for i in "$TSHARK" "$CAPINFOS"
do
if [ ! -x $i ]
then
echo "Couldn't find $i" 1>&2
NOTFOUND=1
fi
done
if [ $NOTFOUND -eq 1 ]
then
exit 1
fi
# Make sure we have at least one file
FOUND=0
for CF in "$@"
do
if [ "$OSTYPE" == "cygwin" ]
then
CF=`cygpath --windows "$CF"`
fi
"$CAPINFOS" "$CF" > /dev/null 2>&1 && FOUND=1
if [ $FOUND -eq 1 ]
then
break
fi
done
if [ $FOUND -eq 0 ] ; then
cat <<FIN
Error: No valid capture files found.
Usage: `basename $0` capture file 1 [capture file 2]...
FIN
exit 1
fi
for CF in "$@" ; do
if [ "$OSTYPE" == "cygwin" ] ; then
CF=`cygpath --windows "$CF"`
fi
if [ ! -f "$CF" ] ; then
echo "Doesn't exist or not a file: $CF" 1>&2
continue
fi
"$CAPINFOS" "$CF" > /dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ] ; then
echo "Not a valid capture file (or some other problem)" 1>&2
continue
fi
printf "%s: " "$CF"
# Extract the protocol names.
$TSHARK -T fields -eframe.protocols -nr "$CF" 2>/dev/null | \
tr ':\r' '\n' | sort -u | tr '\n\r' ' '
printf "\n"
done