trust-dns
不再需要,使用 trust-dns-proto
即可。
use std::env;
use trust_dns_proto::rr::record_type::RecordType;
use trust_dns_resolver::config::*;
use trust_dns_resolver::Resolver;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
eprintln!("Please enter a name to query!");
std::process::exit(1);
}
let query = format!("{}", args[1]);
let resolver = Resolver::new(ResolverConfig::default(), Default::default()).unwrap();
let response = resolver.lookup_ip(query.as_str());
for ans in response.iter() {
println!("{:?}", ans);
}
// 从系统配置创建 /etc/resolv.conf
let resolver = Resolver::from_system_conf().unwrap();
let response = resolver.lookup_ip(query.as_str());
for ans in response.iter() {
println!("{:?}", ans);
}
let ns = resolver.lookup(query.as_str(), RecordType::NS);
for ans in ns.iter() {
println!("{:?}", ans);
}
}