// Server returns the whois server and optional URL for a given query. // Returns an error if it cannot resolve query to any known host. func Server(query string) (string, string, error) { // Queries on TLDs always against IANA if strings.Index(query, ".") < 0 { return IANA, "", nil } z := zonedb.PublicZone(query) if z == nil { return "", "", fmt.Errorf("no public zone found for %s", query) } host := z.WhoisServer() wu := z.WhoisURL() if host != "" { return host, wu, nil } u, err := url.Parse(wu) if err == nil && u.Host != "" { return u.Host, wu, nil } return "", "", fmt.Errorf("no whois server found for %s", query) }
// lookupWhoisServer digs into zonedb to find the whois server for the given // tld. If no server is found (or domain is invalid) an error will be returned. func lookupWhoisServer(domain string) (string, error) { _, err := url.Parse(domain) if err != nil { return "", err } split := strings.Split(domain, ".") // We assume there's at least a 'google' and 'com' if len(split) < 2 { return "", fmt.Errorf("Unable to parse domain (and find tld) for %s (split = %s)", domain, split) } zone := zonedb.PublicZone(domain) if zone == nil { return "", fmt.Errorf("unable to find zone for domain = %s", domain) } host := zone.WhoisServer() if host != "" { return host, nil } return "", fmt.Errorf("error finding whois server (empty host) for domain %s", domain) }