47 lines
847 B
Go
47 lines
847 B
Go
package whois
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
|
|
w "github.com/likexian/whois"
|
|
)
|
|
|
|
func GetExpiration(domain string) (*time.Time, error) {
|
|
result, err := w.Whois(domain)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result = strings.ToLower(result)
|
|
formats := []string{
|
|
"expiration date",
|
|
"expiry date",
|
|
"expires on",
|
|
"paid-till",
|
|
"renewal",
|
|
"expires",
|
|
"domain_datebilleduntil",
|
|
"expiration",
|
|
"registry expiry",
|
|
"registrar registration expiration",
|
|
}
|
|
|
|
for _, format := range formats {
|
|
r, _ := regexp.Compile(fmt.Sprintf(`%s\s*:?\s*([^\s]+)`, format))
|
|
|
|
for i, match := range r.FindStringSubmatch(result) {
|
|
if i%2 == 1 {
|
|
if date, err := time.Parse(time.RFC3339, strings.ToUpper(match)); err == nil {
|
|
return &date, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, errors.New("Expiration date not found")
|
|
}
|