Updoots
This commit is contained in:
parent
48db8e9add
commit
329cb28342
83
src/main.rs
83
src/main.rs
@ -2,6 +2,8 @@ use hickory_resolver::proto::rr::rdata::*;
|
||||
use hickory_resolver::Resolver;
|
||||
use hickory_resolver::config::*;
|
||||
|
||||
use core::fmt;
|
||||
|
||||
// #[derive(Debug)]
|
||||
struct Domain {
|
||||
domain_name: String,
|
||||
@ -10,9 +12,44 @@ struct Domain {
|
||||
aaaa_records: Vec<AAAA>,
|
||||
txt_records: Vec<TXT>,
|
||||
mx_records: Vec<MX>,
|
||||
ns_records: Vec<NS>,
|
||||
soa_records: Vec<SOA>, // Subdomains CAN have there own SOA records if their zones point elsewhere
|
||||
resolver: Resolver
|
||||
}
|
||||
|
||||
impl fmt::Display for Domain {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Domain name: {}\n", self.domain_name)?;
|
||||
write!(f, "DNS Records\n\n")?;
|
||||
for rec in &self.a_records {
|
||||
write!(f, "A: {}\n", rec)?;
|
||||
}
|
||||
for rec in &self.aaaa_records {
|
||||
write!(f, "AAAA: {}\n", rec)?;
|
||||
}
|
||||
for rec in &self.mx_records {
|
||||
write!(f, "MX: {}\n", rec)?;
|
||||
}
|
||||
for rec in &self.txt_records {
|
||||
write!(f, "TXT: {}\n", rec)?;
|
||||
}
|
||||
for rec in &self.ns_records {
|
||||
write!(f, "NS: {}\n", rec)?;
|
||||
}
|
||||
for rec in &self.soa_records {
|
||||
write!(f, "SOA: {}\n", rec)?;
|
||||
}
|
||||
write!(f, "\n\nSubdomains:\n")?;
|
||||
for subdomain in &self.subdomains {
|
||||
write!(f, "{}\n", subdomain.domain_name)?;
|
||||
for rec in &subdomain.a_records {
|
||||
write!(f, "A: {}\n", rec)?;
|
||||
}
|
||||
}
|
||||
write!(f, "\n")
|
||||
}
|
||||
}
|
||||
|
||||
impl Domain {
|
||||
fn new(domain: String) -> Domain {
|
||||
Domain {
|
||||
@ -22,6 +59,8 @@ impl Domain {
|
||||
aaaa_records: vec![],
|
||||
txt_records: vec![],
|
||||
mx_records: vec![],
|
||||
ns_records: vec![],
|
||||
soa_records: vec![],
|
||||
resolver: Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap(),
|
||||
}
|
||||
}
|
||||
@ -48,6 +87,12 @@ impl Domain {
|
||||
// Lookup TXT records
|
||||
self.lookup_txt();
|
||||
|
||||
// Lookup TXT records
|
||||
self.lookup_ns();
|
||||
|
||||
// Lookup TXT records
|
||||
self.lookup_soa();
|
||||
|
||||
// Do subdomains?
|
||||
for subdomain in &mut self.subdomains {
|
||||
// println!("Looking up subdomain: {}", subdomain.domain_name);
|
||||
@ -102,6 +147,30 @@ impl Domain {
|
||||
Err(_err) => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_ns(&mut self) {
|
||||
let response = self.resolver.ns_lookup(&self.domain_name);
|
||||
match response {
|
||||
Ok(rec) => {
|
||||
for entry in rec {
|
||||
self.ns_records.push(entry);
|
||||
}
|
||||
},
|
||||
Err(_err) => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_soa(&mut self) {
|
||||
let response = self.resolver.soa_lookup(&self.domain_name);
|
||||
match response {
|
||||
Ok(rec) => {
|
||||
for entry in rec {
|
||||
self.soa_records.push(entry);
|
||||
}
|
||||
},
|
||||
Err(_err) => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -111,17 +180,7 @@ fn main() {
|
||||
test.append_subdomain("mail".to_string());
|
||||
test.append_subdomain("ftp".to_string());
|
||||
test.lookup_all_records();
|
||||
println!("A Records: {:?}", test.a_records);
|
||||
println!("AAAA Records: {:?}", test.aaaa_records);
|
||||
println!("MX Records: {:?}", test.mx_records);
|
||||
for rec in test.txt_records.iter() {
|
||||
println!("TXT Records: {}", rec);
|
||||
}
|
||||
|
||||
println!("\n\nSubdomains");
|
||||
for subdom in test.subdomains {
|
||||
println!("{}", subdom.domain_name);
|
||||
println!("{:?}", subdom.a_records);
|
||||
}
|
||||
// println!("TXT Records: {:#?}", test.txt_records);
|
||||
println!("{}", test);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user