| Crates.io | microdns |
| lib.rs | microdns |
| version | 0.1.0 |
| created_at | 2025-04-30 15:40:14.177138+00 |
| updated_at | 2025-04-30 15:40:14.177138+00 |
| description | A minimal DNS resolver library with no external dependencies |
| homepage | |
| repository | https://github.com/fschutt/microdns |
| max_upload_size | |
| id | 1655055 |
| size | 27,539 |
A minimal DNS resolver library with zero dependencies, using only the Rust standard library.
Add this to your Cargo.toml:
[dependencies]
microdns = "0.1.0"
use microdns::{lookup_mx_records, Error};
fn main() -> Result<(), Error> {
let mx_records = lookup_mx_records("example.com")?;
for mx in mx_records {
println!("Priority: {}, Server: {}", mx.priority, mx.server);
}
Ok(())
}
use microdns::{lookup_ip_addresses, Error};
fn main() -> Result<(), Error> {
let ips = lookup_ip_addresses("example.com")?;
for ip in ips {
println!("IP: {}", ip);
}
Ok(())
}
use microdns::{resolve_mx_server_ips, Error};
fn main() -> Result<(), Error> {
let server_ips = resolve_mx_server_ips("example.com")?;
for server in server_ips {
println!("Server: {}", server.server);
for ip in server.ip_addresses {
println!(" IP: {}", ip);
}
}
Ok(())
}
use microdns::{lookup_ip_addresses_with_config, DnsConfig, Error};
fn main() -> Result<(), Error> {
// Use custom DNS servers and timeout
let config = DnsConfig {
servers: vec!["1.1.1.1".to_string(), "8.8.8.8".to_string()],
timeout: 3,
};
let ips = lookup_ip_addresses_with_config("example.com", Some(config))?;
for ip in ips {
println!("IP: {}", ip);
}
Ok(())
}
The library defaults to using these DNS servers in order:
MIT license