mdns
– Multicast Domain Name Service
The mdns
module provides basic support for multicast domain name services.
Basic use provides hostname resolution under the .local TLD. This module
also supports DNS Service Discovery that allows for discovering other hosts
that provide a desired service.
Available on these boards
- class mdns.RemoteService
Encapsulates information about a remote service that was found during a search. This object may only be created by a
mdns.Server
. It has no user-visible constructor.Cannot be instantiated directly. Use
mdns.Server.find
.- ipv4_address: ipaddress.IPv4Address | None
IP v4 Address of the remote service. None if no A records are found.
- class mdns.Server(network_interface: wifi.Radio)
The MDNS Server responds to queries for this device’s information and allows for querying other devices.
Constructs or returns the mdns.Server for the given network_interface. (CircuitPython may already be using it.) Only native interfaces are currently supported.
- hostname: str
Hostname resolvable as
<hostname>.local
in addition tocircuitpython.local
. Make sure this is unique across all devices on the network. It defaults tocpy-######
where######
is the hex digits of the last three bytes of the mac address.
- find(service_type: str, protocol: str, *, timeout: float = 1) Tuple[RemoteService]
Find all locally available remote services with the given service type and protocol.
This doesn’t allow for direct hostname lookup. To do that, use
socketpool.SocketPool.getaddrinfo()
.
- advertise_service(*, service_type: str, protocol: str, port: int) None
Respond to queries for the given service with the given port.
service_type
andprotocol
can only occur on one port. Any call after the first will update the entry’s port.If web workflow is active, the port it uses can’t also be used to advertise a service.
Limitations: Publishing up to 32 TXT records is only supported on the RP2040 Pico W board at this time.