Added some error handling to my regex lookups
Adde notes for other TLD support
This commit is contained in:
parent
670eb3937f
commit
6aeaa04fce
25
notes.md
Normal file
25
notes.md
Normal file
@ -0,0 +1,25 @@
|
||||
### UK specific regex
|
||||
|
||||
Nameservers
|
||||
```rs
|
||||
r"(?i)(Name servers:\n)(.*\n)+"
|
||||
```
|
||||
|
||||
Tag
|
||||
|
||||
`This is a bad way of doing this, will use the below method instead`
|
||||
```rs
|
||||
r"(?i)(\[TAG = )(\w+-\w+-\w+)"
|
||||
```
|
||||
|
||||
Status
|
||||
```rs
|
||||
r"(?i)(Registration status:\n)(.*)"
|
||||
```
|
||||
|
||||
Registrar
|
||||
|
||||
`This will also return the tag which we can separate that out later`
|
||||
```rs
|
||||
r"(?i)(Registrar:\n)(.*)"
|
||||
```
|
||||
26
src/whois.rs
26
src/whois.rs
@ -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(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user