Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_process_path(tshark_path=None, process_name="tshark"):
"""Finds the path of the tshark executable.
If the user has provided a path
or specified a location in config.ini it will be used. Otherwise default
locations will be searched.
:param tshark_path: Path of the tshark binary
:raises TSharkNotFoundException in case TShark is not found in any location.
"""
config = get_config()
possible_paths = [config.get(process_name, "%s_path" % process_name)]
# Add the user provided path to the search list
if tshark_path is not None:
possible_paths.insert(0, tshark_path)
# Windows search order: configuration file"s path, common paths.
if sys.platform.startswith("win"):
for env in ("ProgramFiles(x86)", "ProgramFiles"):
program_files = os.getenv(env)
if program_files is not None:
possible_paths.append(
os.path.join(program_files, "Wireshark", "%s.exe" % process_name)
)
# Linux, etc. search order: configuration file's path, the system's path
else:
def get_tshark_path():
"""
Finds the path of the tshark executable. If the user has specified a
location in config.ini it will be used. Otherwise default locations
will be searched.
:raises TSharkNotFoundException in case TShark is not found in any location.
"""
config = get_config()
possible_paths = [config.get('tshark', 'tshark_path')]
# Windows search order: configuration file's path, common paths.
if sys.platform.startswith('win'):
for env in ('ProgramFiles(x86)', 'ProgramFiles'):
program_files = os.getenv(env)
if program_files is not None:
possible_paths.append(
os.path.join(program_files, 'Wireshark', 'tshark.exe')
)
# Linux, etc. search order: configuration file's path, the system's path
else:
os_path = os.getenv(
'PATH',
'/usr/bin:/usr/sbin:/usr/lib/tshark:/usr/local/bin'
)