Skip to content

Conversation

kmikov
Copy link

@kmikov kmikov commented Feb 11, 2025

Fix version parsing when the version number is not on the first line due to plugins.

Fix version parsing when the version number is not on the first line due to plugins.
@kmikov
Copy link
Author

kmikov commented Feb 11, 2025

Additional info:

Tshark supports lua plugins in ~/.local/lib/wireshark/plugins/
If you have a lua plugin that prints some info it will be displayed everytime tshark starts. For example like this:

$ tshark -v
Loading test.lua
TShark (Wireshark) 4.2.2 (Git v4.2.2 packaged as 4.2.2-1.1build3).

Copyright 1998-2024 Gerald Combs <[email protected]> and contributors.
Licensed under the terms of the GNU General Public License (version 2 or later).

This gives the following exception:

Traceback (most recent call last):
  File "/home/kmikov/GIT/python_test/test.py", line 3, in <module>
    print(get_tshark_version())
          ^^^^^^^^^^^^^^^^^^^^
  File "/home/kmikov/GIT/python_test/.venv/lib/python3.12/site-packages/pyshark/tshark/tshark.py", line 85, in get_tshark_version
    raise TSharkVersionException("Unable to parse TShark version from: {}".format(version_line))
pyshark.tshark.tshark.TSharkVersionException: Unable to parse TShark version from: Loading test.lua

The fix checks every line and searches for the first hit with the regex. Of course someone can print another version numbers from the lua script, but at least pyshark won't throw an exception.

@kmikov kmikov changed the title Update tshark.py Fix version parsing Feb 11, 2025
@@ -82,13 +82,16 @@ def get_tshark_version(tshark_path=None):
with open(os.devnull, "w") as null:
version_output = subprocess.check_output(parameters, stderr=null).decode("ascii")

version_line = version_output.splitlines()[0]
version_lines = version_output.splitlines()
version_string = None
pattern = r'.*\s(\d+\.\d+\.\d+).*' # match " #.#.#" version pattern
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional regex to further narrow the version

Suggested change
pattern = r'.*\s(\d+\.\d+\.\d+).*' # match " #.#.#" version pattern
pattern = r'^TShark.*?\s(\d+\.\d+\.\d+).*' # match " #.#.#" version pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant