mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2024-11-10 08:37:21 +01:00
Added support for CNAME, NS and SOA records
This commit is contained in:
parent
4881f76b5b
commit
b900ec3b1c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1210,6 +1210,7 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml",
|
||||||
"tower",
|
"tower",
|
||||||
|
"trust-dns-proto",
|
||||||
"trust-dns-resolver",
|
"trust-dns-resolver",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -18,5 +18,6 @@ tokio = { version = "1", features = ["full"] }
|
|||||||
tera = "1"
|
tera = "1"
|
||||||
toml = "0.7"
|
toml = "0.7"
|
||||||
tower = "*"
|
tower = "*"
|
||||||
|
trust-dns-proto = "0.22"
|
||||||
trust-dns-resolver = "0.22"
|
trust-dns-resolver = "0.22"
|
||||||
maxminddb = "0.23"
|
maxminddb = "0.23"
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
* It does not aim to be reusable for any other purpose,
|
* It does not aim to be reusable for any other purpose,
|
||||||
* the trust_dns_resolver library already does that.
|
* the trust_dns_resolver library already does that.
|
||||||
*/
|
*/
|
||||||
|
use trust_dns_proto::rr::{
|
||||||
|
record_type::RecordType,
|
||||||
|
RData,
|
||||||
|
};
|
||||||
use trust_dns_resolver::{
|
use trust_dns_resolver::{
|
||||||
TokioAsyncResolver,
|
TokioAsyncResolver,
|
||||||
error::*,
|
error::*,
|
||||||
@ -18,9 +21,12 @@ use std::net::IpAddr;
|
|||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize, Default, Clone)]
|
#[derive(serde::Deserialize, serde::Serialize, Default, Clone)]
|
||||||
pub struct DnsLookupResult {
|
pub struct DnsLookupResult {
|
||||||
a: Vec<IpAddr>,
|
a: Vec<IpAddr>,
|
||||||
aaaa: Vec<IpAddr>,
|
aaaa: Vec<IpAddr>,
|
||||||
mx: Vec<MxRecord>,
|
cname: Vec<String>,
|
||||||
|
mx: Vec<MxRecord>,
|
||||||
|
ns: Vec<String>,
|
||||||
|
soa: Vec<SoaRecord>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(serde::Deserialize, serde::Serialize, Clone)]
|
||||||
@ -29,6 +35,17 @@ pub struct MxRecord {
|
|||||||
exchange: String,
|
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*/
|
/* Lookup Functions*/
|
||||||
|
|
||||||
pub async fn reverse_lookup(
|
pub async fn reverse_lookup(
|
||||||
@ -67,7 +84,8 @@ pub async fn lookup(
|
|||||||
do_full_lookup: bool,
|
do_full_lookup: bool,
|
||||||
) -> DnsLookupResult {
|
) -> DnsLookupResult {
|
||||||
let ipv4_lookup_res = resolver.ipv4_lookup(name);
|
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
|
// initlize an empty lookup result
|
||||||
let mut dig_result: DnsLookupResult = Default::default();
|
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 {
|
if do_full_lookup {
|
||||||
let mx_lookup_res = resolver.mx_lookup(name);
|
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 {
|
match mx_lookup_res.await {
|
||||||
Ok(lookup) => {
|
Ok(lookup) => {
|
||||||
@ -110,6 +144,37 @@ pub async fn lookup(
|
|||||||
println!("There was an error while looking MX up {name}: {e}");
|
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
|
return dig_result
|
||||||
|
Loading…
Reference in New Issue
Block a user