diff --git a/Cargo.lock b/Cargo.lock index b16ffa2..c8b5a62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1210,6 +1210,7 @@ dependencies = [ "tokio", "toml", "tower", + "trust-dns-proto", "trust-dns-resolver", ] diff --git a/Cargo.toml b/Cargo.toml index 66af771..4a34067 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,6 @@ tokio = { version = "1", features = ["full"] } tera = "1" toml = "0.7" tower = "*" +trust-dns-proto = "0.22" trust-dns-resolver = "0.22" maxminddb = "0.23" diff --git a/src/simple_dns.rs b/src/simple_dns.rs index 4465071..0742288 100644 --- a/src/simple_dns.rs +++ b/src/simple_dns.rs @@ -5,7 +5,10 @@ * It does not aim to be reusable for any other purpose, * the trust_dns_resolver library already does that. */ - +use trust_dns_proto::rr::{ + record_type::RecordType, + RData, +}; use trust_dns_resolver::{ TokioAsyncResolver, error::*, @@ -18,9 +21,12 @@ use std::net::IpAddr; #[derive(serde::Deserialize, serde::Serialize, Default, Clone)] pub struct DnsLookupResult { - a: Vec, - aaaa: Vec, - mx: Vec, + a: Vec, + aaaa: Vec, + cname: Vec, + mx: Vec, + ns: Vec, + soa: Vec, } #[derive(serde::Deserialize, serde::Serialize, Clone)] @@ -29,6 +35,17 @@ pub struct MxRecord { exchange: String, } +#[derive(serde::Deserialize, serde::Serialize, Clone)] +pub struct SoaRecord { + mname: String, + rname: String, + serial: u32, + refresh: i32, + retry: i32, + expire: i32, + minimum: u32, +} + /* Lookup Functions*/ pub async fn reverse_lookup( @@ -67,7 +84,8 @@ pub async fn lookup( do_full_lookup: bool, ) -> DnsLookupResult { let ipv4_lookup_res = resolver.ipv4_lookup(name); - let ipv6_lookup_res = resolver.ipv6_lookup(name); + let ipv6_lookup_res = resolver.ipv6_lookup(name); + let cname_lookup_res = resolver.lookup(name, RecordType::CNAME); // initlize an empty lookup result let mut dig_result: DnsLookupResult = Default::default(); @@ -94,8 +112,24 @@ pub async fn lookup( } } + match cname_lookup_res.await { + Ok(lookup) => { + for record in lookup { + match record { + RData::CNAME(cname) => dig_result.cname.push(cname.to_string()), + _ => {}, + } + } + } + Err(e) => { + println!("There was an error while looking CNAME up {name}: {e}"); + } + } + if do_full_lookup { let mx_lookup_res = resolver.mx_lookup(name); + let ns_lookup_res = resolver.ns_lookup(name); + let soa_lookup_res = resolver.soa_lookup(name); match mx_lookup_res.await { Ok(lookup) => { @@ -110,6 +144,37 @@ pub async fn lookup( println!("There was an error while looking MX up {name}: {e}"); } } + + match ns_lookup_res.await { + Ok(lookup) => { + for ns in lookup { + dig_result.ns.push(ns.to_string()); + } + } + Err(e) => { + println!("There was an error while looking NS up {name}: {e}"); + } + } + + match soa_lookup_res.await { + Ok(lookup) => { + for soa in lookup { + dig_result.soa.push(SoaRecord{ + mname: soa.mname().to_string(), + rname: soa.rname().to_string(), + serial: soa.serial(), + refresh: soa.refresh(), + retry: soa.retry(), + expire: soa.expire(), + minimum: soa.minimum(), + }); + } + } + Err(e) => { + println!("There was an error while looking MX up {name}: {e}"); + } + } + } return dig_result