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') for path in os_path.split(':'): possible_paths.append(os.path.join(path, 'tshark')) for path in possible_paths: if os.path.exists(path): return path raise TSharkNotFoundException( 'TShark not found. Try adding its location to the configuration file. ' 'Search these paths: {}'.format(possible_paths))
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() if sys.platform.startswith('win'): win32_progs = os.environ['ProgramFiles(x86)'] win64_progs = os.environ['ProgramFiles'] tshark_path = ('Wireshark', 'tshark.exe') possible_paths = [config.get('tshark', 'tshark_path'), os.path.join(win32_progs, *tshark_path), os.path.join(win64_progs, *tshark_path)] else: possible_paths = [config.get('tshark', 'tshark_path'), '/usr/bin/tshark', '/usr/lib/tshark', '/usr/local/bin/tshark'] for path in possible_paths: if os.path.exists(path): return path raise TSharkNotFoundException('TShark not found in the following locations: ' + ', '.join(possible_paths) + ' Either place tshark there or add more paths to the config file.')
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' ) for path in os_path.split(':'): possible_paths.append(os.path.join(path, 'tshark')) for path in possible_paths: if os.path.exists(path): return path raise TSharkNotFoundException( 'TShark not found. Try adding its location to the configuration file. ' 'Search these paths: {}'.format(possible_paths) )
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() if sys.platform.startswith('win'): win32_progs = os.environ.get('ProgramFiles(x86)', '') win64_progs = os.environ.get('ProgramFiles', '') tshark_path = ('Wireshark', 'tshark.exe') possible_paths = [ config.get('tshark', 'tshark_path'), os.path.join(win32_progs, *tshark_path), os.path.join(win64_progs, *tshark_path) ] else: possible_paths = [ config.get('tshark', 'tshark_path'), '/usr/bin/tshark', '/usr/lib/tshark', '/usr/local/bin/tshark' ] for path in possible_paths: if os.path.exists(path): return path raise TSharkNotFoundException( 'TShark not found in the following locations: ' + ', '.join(possible_paths) + ' Either place tshark there or add more paths to the config file.')
def get_tshark_path(): """ Finds the path of the tshark executable according to the list in the configuration. :raises TSharkNotFoundException in case TShark is not found in any location. """ config = get_config() if sys.platform.startswith('win'): possible_paths = config.get('tshark', 'windows_paths').split(',') else: possible_paths = config.get('tshark', 'linux_paths').split(',') for path in possible_paths: if os.path.exists(path): return path raise TSharkNotFoundException('TShark not found in the following locations: ' + ', '.join(possible_paths) + ' Either place tshark there or add more paths to the config file.')
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: os_path = os.getenv( "PATH", "/usr/bin:/usr/sbin:/usr/lib/tshark:/usr/local/bin" ) for path in os_path.split(":"): possible_paths.append(os.path.join(path, process_name)) for path in possible_paths: if os.path.exists(path): if sys.platform.startswith("win"): path = path.replace("\\", "/") return path raise TSharkNotFoundException( "TShark not found. Try adding its location to the configuration file. " "Searched these paths: {}".format(possible_paths) )
def get_tshark_path(): """ Finds the path of the tshark executable according to the list in the configuration. :raises TSharkNotFoundException in case TShark is not found in any location. """ config = get_config() if sys.platform.startswith('win'): possible_paths = config.get('tshark', 'windows_paths').split(',') else: possible_paths = config.get('tshark', 'linux_paths').split(',') for path in possible_paths: if os.path.exists(path): return path raise TSharkNotFoundException( 'TShark not found in the following locations: ' + ', '.join(possible_paths) + ' Either place tshark there or add more paths to the config file.')
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: os_path = os.getenv( 'PATH', '/usr/bin:/usr/sbin:/usr/lib/tshark:/usr/local/bin' ) for path in os_path.split(':'): possible_paths.append(os.path.join(path, process_name)) for path in possible_paths: if os.path.exists(path): if sys.platform.startswith('win'): path = path.replace("\\", "/") return path raise TSharkNotFoundException( 'TShark not found. Try adding its location to the configuration file. ' 'Searched these paths: {}'.format(possible_paths) )