From 99d4a210f95463a2635e32679245e63aeac0c399 Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Sun, 24 Mar 2024 19:34:38 +1100 Subject: [PATCH] Cleaned up whois library and started AU support --- src/whois.rs | 79 +++++++++++++++++----------------------------------- 1 file changed, 26 insertions(+), 53 deletions(-) diff --git a/src/whois.rs b/src/whois.rs index 6fc7d4d..aa42be4 100644 --- a/src/whois.rs +++ b/src/whois.rs @@ -65,12 +65,19 @@ impl Registrant { } } +struct Eligibility { + e_type: String, + id: String, + name: String, +} + pub struct WhoisData { registrar: String, domain_status: String, registrant: Vec, nameservers: Vec, dnssec: String, + eligibility_type: Option, } impl fmt::Display for WhoisData { @@ -98,63 +105,15 @@ impl WhoisData { 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 = RegexQuery::new(String::from(r"(?i)(nameservers*:|name servers*:)(.*)")); let dnssec_regex = RegexQuery::new(String::from(r"(?i)(.*dnssec:)(.*)")); - let registrar_caps = registrar_regex.get_matches(&result); - let registrar: String; - match registrar_caps.get(0) { - Some(reg) => { - registrar = reg.to_string(); - } - None => { - registrar = String::from("None"); - } - } - 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) { - Some(name) => { - reg_name = name.to_string(); - } - None => { - reg_name = String::from("None"); - } - } - - let reg_org_caps = registrant_org_regex.get_matches(&result); - let reg_org: String; - match reg_org_caps.get(0) { - Some(org) => { - reg_org = org.to_string(); - } - None => { - reg_org = String::from("None"); - } - } - - let reg_email_caps = registrant_email_regex.get_matches(&result); - let reg_email: String; - match reg_email_caps.get(0) { - Some(email) => { - reg_email = email.to_string(); - } - None => { - reg_email = String::from("None"); - } - } + let registrar = WhoisData::parse_whois(registrar_regex.get_matches(&result), 0); + let domain_status = WhoisData::parse_whois(domain_status_regex.get_matches(&result), 0); + let reg_name = WhoisData::parse_whois(registrant_name_regex.get_matches(&result), 0); + let reg_org = WhoisData::parse_whois(registrant_org_regex.get_matches(&result), 0); + let reg_email = WhoisData::parse_whois(registrant_email_regex.get_matches(&result), 0); let mut nameservers = vec![]; for nameserver in nameserver_regex.get_matches(&result) { @@ -174,6 +133,20 @@ impl WhoisData { )], nameservers: nameservers, dnssec: dnssec[0].clone(), + eligibility_type: None, } } + + fn parse_whois(caps: Vec, index: usize) -> String { + let data: String; + match caps.get(index) { + Some(tmp) => { + data = tmp.to_string(); + } + None => { + data = String::from("None"); + } + } + data + } }