Skip to content

Commit

Permalink
fix: Add support for *.ua TLDs and com.br
Browse files Browse the repository at this point in the history
  • Loading branch information
TwiN committed Jun 28, 2023
1 parent 9ff5df5 commit 7904194
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 12 additions & 6 deletions whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ 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
Expand All @@ -74,7 +72,16 @@ func (c *Client) Query(domain string) (string, error) {
return c.query(cachedWHOISServer, domain)
}
}
output, err := c.query(c.whoisServerAddress, domainExtension)
var output string
var err error
if domainExtension == "ua" {
if len(parts) > 2 && len(parts[len(parts)-2]) < 4 {
domainExtension = parts[len(parts)-2] + "." + domainExtension
}
output, err = c.query("whois."+domainExtension+":43", domain)
} else {
output, err = c.query(c.whoisServerAddress, domainExtension)
}
if err != nil {
return "", err
}
Expand Down Expand Up @@ -140,15 +147,14 @@ func (c Client) QueryAndParse(domain string) (*Response, error) {
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"):
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") || strings.Contains(key, "nserver")) {
} else if strings.Contains(key, "name server") || strings.Contains(key, "nserver") {
response.NameServers = append(response.NameServers, value)
}
}
Expand Down
8 changes: 4 additions & 4 deletions whois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ func TestClient(t *testing.T) {
wantErr: true,
},
{
domain: "google.com.br",
domain: "google.com.br", // name.com.br is handled weirdly by whois.registro.br, so we'll use this instead
wantErr: false,
},
{
domain: "xyz.co.ua",
domain: "name.co.ua",
wantErr: false,
},
{
domain: "xyz.pp.ua",
domain: "name.pp.ua",
wantErr: false,
},
}
client := NewClient().WithReferralCache(true)
client := NewClient().WithReferralCache(false)
for _, scenario := range scenarios {
t.Run(scenario.domain+"_Query", func(t *testing.T) {
output, err := client.Query(scenario.domain)
Expand Down

0 comments on commit 7904194

Please sign in to comment.