Added some error handling to my regex lookups

Adde notes for other TLD support
This commit is contained in:
benjamyn committed 2024-03-23 19:27:34 +11:00
1 parent 670eb3937f
commit 6aeaa04fce
2 files changed
+43 -8

No files matched your search

+18 -8
View File
@@ -1,7 +1,5 @@
use core::fmt;
use hickory_resolver::{proto::rr::rdata::name, Name};
use regex::Regex;
use std::fmt::Write as _;
use whois_rust::{WhoIs, WhoIsLookupOptions};
#[derive(Debug)]
@@ -91,11 +89,14 @@ impl WhoisData {
let result: String = whois
.lookup(WhoIsLookupOptions::from_string(domain).unwrap())
.unwrap();
let registrar_regex = RegexQuery::new(String::from(r"(?i)(.*registrar:)(.*)"));
let domain_status_regex = RegexQuery::new(String::from(r"(?i)(.*domain status:)(.*)"));
let registrar_regex =
RegexQuery::new(String::from(r"(?i)(.*registrar:|registrar *name:)(.*)"));
let domain_status_regex =
RegexQuery::new(String::from(r"(?i)(.*domain status:|.*status:)(.*)"));
// TODO: Capture the registrant info for each type
let registrant_name_regex = RegexQuery::new(String::from(r"(?i)(registrant name:)(.*)"));
let registrant_org_regex = RegexQuery::new(String::from(r"(?i)(registrant org.*:)(.*)"));
let registrant_name_regex = RegexQuery::new(String::from(r"(?i)(registrant.*name:)(.*)"));
let registrant_org_regex =
RegexQuery::new(String::from(r"(?i)(registrant org.*:|registrant:)(.*)"));
let registrant_email_regex = RegexQuery::new(String::from(r"(?i)(registrant email:)(.*)"));
let nameserver_regex =
@@ -112,7 +113,16 @@ impl WhoisData {
registrar = String::from("None");
}
}
let domain_status = domain_status_regex.get_matches(&result);
let domain_status_caps = domain_status_regex.get_matches(&result);
let domain_status: String;
match domain_status_caps.get(0) {
Some(status) => {
domain_status = status.to_string();
}
None => {
domain_status = String::from("None");
}
}
let reg_name_caps = registrant_name_regex.get_matches(&result);
let reg_name: String;
match reg_name_caps.get(0) {
@@ -155,7 +165,7 @@ impl WhoisData {
// println!("{:?}", registrar[0]);
WhoisData {
registrar: registrar.clone(),
domain_status: domain_status[0].clone(),
domain_status: domain_status.clone(),
registrant: vec![Registrant::new(
reg_name.clone(),
reg_org.clone(),