trust-dns 不再需要,使用 trust-dns-proto 即可。

    1. use std::env;
    2. use trust_dns_proto::rr::record_type::RecordType;
    3. use trust_dns_resolver::config::*;
    4. use trust_dns_resolver::Resolver;
    5. fn main() {
    6. let args: Vec<String> = env::args().collect();
    7. if args.len() != 2 {
    8. eprintln!("Please enter a name to query!");
    9. std::process::exit(1);
    10. }
    11. let query = format!("{}", args[1]);
    12. let resolver = Resolver::new(ResolverConfig::default(), Default::default()).unwrap();
    13. let response = resolver.lookup_ip(query.as_str());
    14. for ans in response.iter() {
    15. println!("{:?}", ans);
    16. }
    17. // 从系统配置创建 /etc/resolv.conf
    18. let resolver = Resolver::from_system_conf().unwrap();
    19. let response = resolver.lookup_ip(query.as_str());
    20. for ans in response.iter() {
    21. println!("{:?}", ans);
    22. }
    23. let ns = resolver.lookup(query.as_str(), RecordType::NS);
    24. for ans in ns.iter() {
    25. println!("{:?}", ans);
    26. }
    27. }