Skip to content

Instantly share code, notes, and snippets.

@Bas-Man
Created March 28, 2021 14:06
Show Gist options
  • Save Bas-Man/eb35052052066903ec9ffe9eac57a55b to your computer and use it in GitHub Desktop.
Save Bas-Man/eb35052052066903ec9ffe9eac57a55b to your computer and use it in GitHub Desktop.
trust-dns-resolver looking up TXT records in Rust
use trust_dns_resolver::error::ResolveResult;
use trust_dns_resolver::Resolver;
use trust_dns_resolver::{config::*, lookup::TxtLookup};
fn main() {
// Construct a new Resolver with default configuration options
let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap();
// Lookup the IP addresses associated with a name.
// The final dot forces this to be an FQDN, otherwise the search rules as specified
// in `ResolverOpts` will take effect. FQDN's are generally cheaper queries.
let txt_response = resolver.txt_lookup("gmail.com.");
display_txt(&txt_response);
}
fn display_txt(txt_response: &ResolveResult<TxtLookup>) {
match txt_response {
Err(_) => println!("No TXT Records."),
Ok(txt_response) => {
let mut i = 1;
for record in txt_response.iter() {
println!("TXT Record {}:", i);
println!("{}", record.to_string());
println!("");
i = i + 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment