Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dylanmckay/mdns
A multicast DNS client in Rust
https://github.com/dylanmckay/mdns
Last synced: about 1 month ago
JSON representation
A multicast DNS client in Rust
- Host: GitHub
- URL: https://github.com/dylanmckay/mdns
- Owner: dylanmckay
- License: mit
- Created: 2016-11-27T07:50:00.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T09:51:26.000Z (6 months ago)
- Last Synced: 2024-10-06T02:31:03.603Z (about 1 month ago)
- Language: Rust
- Size: 77.1 KB
- Stars: 115
- Watchers: 4
- Forks: 45
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mdns
[![Build Status](https://travis-ci.org/dylanmckay/mdns.svg?branch=master)](https://travis-ci.org/dylanmckay/mdns)
[![crates.io](https://img.shields.io/crates/v/mdns.svg)](https://crates.io/crates/mdns)
[![MIT license](https://img.shields.io/github/license/mashape/apistatus.svg)]()[Documentation](https://docs.rs/mdns)
An multicast DNS client in Rust.
Error logging is handled with the `log` library.
[Wikipedia](https://en.wikipedia.org/wiki/Multicast_DNS)
## Example
Find IP addresses for all Chromecasts on the local network.
```rust
use futures_util::{pin_mut, stream::StreamExt};
use mdns::{Error, Record, RecordKind};
use std::{net::IpAddr, time::Duration};const SERVICE_NAME: &'static str = "_googlecast._tcp.local";
#[async_std::main]
async fn main() -> Result<(), Error> {
// Iterate through responses from each Cast device, asking for new devices every 15s
let stream = mdns::discover::all(SERVICE_NAME, Duration::from_secs(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 to_ip_addr(record: &Record) -> Option {
match record.kind {
RecordKind::A(addr) => Some(addr.into()),
RecordKind::AAAA(addr) => Some(addr.into()),
_ => None,
}
}
```