diff --git a/whois.go b/whois.go index 86e2ea6..61cf624 100644 --- a/whois.go +++ b/whois.go @@ -12,7 +12,7 @@ const ( ianaWHOISServerAddress = "whois.iana.org:43" ) -var tldWithoutExpirationDate = []string{"at","be","ch","co.at","com.br","or.at","de","fr","me","mx","nl"} +var tldWithoutExpirationDate = []string{"at", "be", "ch", "co.at", "com.br", "or.at", "de", "fr", "me", "mx", "nl"} type Client struct { whoisServerAddress string @@ -47,18 +47,20 @@ func (c *Client) WithReferralCache(enabled bool) *Client { "org": "whois.publicinterestregistry.org", "red": "whois.nic.red", "sh": "whois.nic.sh", + "co.ua": "whois.ua", + "pp.ua": "whois.ua", } } return c } func doesTLDHaveExpirationDate(e string) bool { - for _, a := range tldWithoutExpirationDate { - if a == e { - return true - } - } - return false + for _, a := range tldWithoutExpirationDate { + if a == e { + return true + } + } + return false } func (c *Client) Query(domain string) (string, error) { @@ -135,10 +137,18 @@ func (c Client) QueryAndParse(domain string) (*Response, error) { key := strings.ToLower(strings.TrimSpace(line[:valueStartIndex])) value := strings.TrimSpace(line[valueStartIndex+1:]) if response.ExpirationDate.Unix() != 0 && strings.Contains(key, "expir") && strings.Contains(key, "date") { - response.ExpirationDate, _ = time.Parse(time.RFC3339, strings.ToUpper(value)) - } else if strings.Contains(key, "domain status") { + switch { + case strings.HasSuffix(domain, ".br"): + response.ExpirationDate, _ = time.Parse("20060102", strings.ToUpper(value)) + case strings.HasSuffix(domain, "co.ua"), + strings.HasSuffix(domain, "pp.ua"): + response.ExpirationDate, _ = time.Parse("02-Jan-2006 03:04:05 MST", strings.ToUpper(value)) + default: + response.ExpirationDate, _ = time.Parse(time.RFC3339, strings.ToUpper(value)) + } + } else if strings.Contains(key, "status") { response.DomainStatuses = append(response.DomainStatuses, value) - } else if strings.Contains(key, "name server") { + } else if (strings.Contains(key, "name server") || strings.Contains(key, "nserver")) { response.NameServers = append(response.NameServers, value) } } diff --git a/whois_test.go b/whois_test.go index 1e9f778..f01f888 100644 --- a/whois_test.go +++ b/whois_test.go @@ -51,6 +51,18 @@ func TestClient(t *testing.T) { domain: "name.de", wantErr: true, }, + { + domain: "google.com.br", + wantErr: false, + }, + { + domain: "xyz.co.ua", + wantErr: false, + }, + { + domain: "xyz.pp.ua", + wantErr: false, + }, } client := NewClient().WithReferralCache(true) for _, scenario := range scenarios {