An multicast DNS client in Rust.
Find IP addresses for all Chromecasts on the local network.
```rust use futuresutil::{pinmut, stream::StreamExt}; use mdns::{Error, Record, RecordKind}; use std::{net::IpAddr, time::Duration};
const SERVICENAME: &'static str = "googlecast._tcp.local";
async fn main() -> Result<(), Error> { // Iterate through responses from each Cast device, asking for new devices every 15s let stream = mdns::discover::all(SERVICENAME, Duration::fromsecs(15))?.listen(); pin_mut!(stream);
while let Some(Ok(response)) = stream.next().await {
let addr = response.records()
.filter_map(self::to_ip_addr)
.next();
if let Some(addr) = addr {
println!("found cast device at {}", addr);
} else {
println!("cast device does not advertise address");
}
}
Ok(())
}
fn toipaddr(record: &Record) -> Option