diff --git a/man/wsdd.8 b/man/wsdd.8 index 7c06dc4..b7855b9 100644 --- a/man/wsdd.8 +++ b/man/wsdd.8 @@ -162,10 +162,12 @@ only. The following commands can be issued: Clears the list of all discovered devices. Use the \fBprobe\fR command to search for devices again. This command does not return any data and is only available in discover mode. -.SS \fBlist\fR - List discovered devices -Returns a tab-separated list of discovered devices with the following information. -The possibly empty list of detected hosts is always terminated with a single -dot ('.') in an otherwise empty line. This command is only available in discover mode. +.SS \fBlist \fI[TYPE]\fR - List discovered devices +Returns a tab-separated list of discovered devices of the provided TYPE (e.g. +"pub:Computer") with the following information. If no type is provided, all +discovered devices are listed. The possibly empty list of detected hosts is +always terminated with a single dot ('.') in an otherwise empty line. This +command is only available in discover mode. .TP UUID UUID of the discovered device. Note that a multi-homed device should appear diff --git a/src/wsdd.py b/src/wsdd.py index 39f54c9..da9e4a8 100755 --- a/src/wsdd.py +++ b/src/wsdd.py @@ -680,7 +680,7 @@ def extract_wsdp_props(self, root: ElementTree.Element, dialect: str) -> None: def extract_host_props(self, root: ElementTree.Element) -> None: types = root.findtext('wsdp:Types', '', namespaces) - self.props['types'] = types.split(' ')[0] + self.props['types'] = types.split(' ') if types != PUB_COMPUTER: return @@ -1162,7 +1162,8 @@ def handle_command(self, line: str, write_stream: asyncio.StreamWriter) -> None: logger.debug('clearing list of known devices') WSDDiscoveredDevice.instances.clear() elif command == 'list' and args.discovery: - write_stream.write(bytes(self.get_list_reply(), 'utf-8')) + wsd_type = command_args[0] if command_args else None + write_stream.write(bytes(self.get_list_reply(wsd_type), 'utf-8')) elif command == 'quit': write_stream.close() elif command == 'start': @@ -1175,9 +1176,12 @@ def handle_command(self, line: str, write_stream: asyncio.StreamWriter) -> None: def get_clients_by_interface(self, interface: Optional[str]) -> List[WSDClient]: return [c for c in WSDClient.instances if c.mch.address.interface.name == interface or not interface] - def get_list_reply(self) -> str: + def get_list_reply(self, wsd_type: Optional[str]) -> str: retval = '' for dev_uuid, dev in WSDDiscoveredDevice.instances.items(): + if wsd_type and (('types' not in dev.props) or (wsd_type not in dev.props['types'])): + continue + addrs_str = [] for addrs in dev.addresses.items(): addrs_str.append(', '.join(['{}'.format(a) for a in addrs]))