Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/pyshark/tshark/tshark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

m = re.match(pattern, version_line)
if not m:
raise TSharkVersionException("Unable to parse TShark version from: {}".format(version_line))
version_string = m.groups()[0] # Use first match found

for version_line in version_lines:
m = re.match(pattern, version_line)
if m:
version_string = m.groups()[0] # Use first match found
break
if not version_string:
raise TSharkVersionException("Unable to parse TShark version from: {}".format(version_lines))
return version.parse(version_string)


Expand Down