Documentation
¶
Overview ¶
Package whois queries domain registration data.
Lookup strategy (per https://deployment.rdap.org/ deployment status):
- RDAP is attempted first via the rdap.org bootstrap service, which redirects to the authoritative RDAP server for the TLD based on the IANA bootstrap registry (https://data.iana.org/rdap/dns.json).
- If the TLD has no RDAP deployment (rdap.org answers 404 without a redirect), the client falls back to the classic WHOIS protocol on TCP port 43. The responsible server is resolved from an embedded table, falling back to a whois.iana.org referral lookup.
WHOIS responses differ wildly per registry, so parsing is best-effort: a generic key/value parser plus per-TLD rules (jp, uk, br, eu, it, ...) normalize the common fields (dates, registrar, name servers, status).
Usage:
c := whois.New()
rec, err := c.Query("example.com")
if err != nil { ... }
fmt.Println(rec.Source, rec.Registered, rec.Parsed.Expiry)
The zero-dependency package also exposes Parse (for offline WHOIS parsing) and ToASCII (IDN conversion) for reuse.
Index ¶
- Variables
- func IsAvailable(tld, raw string) bool
- func ToASCII(domain string) (string, error)
- type Client
- type Contact
- type Option
- func WithHTTPClient(h *http.Client) Option
- func WithIANAServer(server string) Option
- func WithPreferRDAP(v bool) Option
- func WithRDAPBaseURL(u string) Option
- func WithReferralFollowing(v bool) Option
- func WithTimeout(d time.Duration) Option
- func WithWhoisFallback(v bool) Option
- func WithWhoisServer(tld, server string) Option
- type ParsedInfo
- type Record
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoRDAP is returned (wrapped) when the TLD has no RDAP deployment. // With fallback enabled this is handled internally. ErrNoRDAP = errors.New("whois: TLD has no RDAP service") // ErrNoWhoisServer is returned when no port-43 server is known for a TLD. ErrNoWhoisServer = errors.New("whois: no WHOIS server known for TLD") )
Errors returned by the client.
Functions ¶
func IsAvailable ¶
IsAvailable reports whether a raw WHOIS response indicates that the domain is not registered.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client queries domain registration data. It is safe for concurrent use.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client used for RDAP requests.
func WithIANAServer ¶
WithIANAServer overrides the bootstrap WHOIS server used to discover unknown TLD servers (default whois.iana.org).
func WithPreferRDAP ¶
WithPreferRDAP toggles trying RDAP before WHOIS (default true).
func WithRDAPBaseURL ¶
WithRDAPBaseURL replaces the RDAP endpoint (default https://rdap.org). A custom URL is treated as an authoritative RDAP server: a 404 then means "domain not found" instead of "TLD without RDAP".
func WithReferralFollowing ¶
WithReferralFollowing toggles following the "Registrar WHOIS Server" referral found in thin-registry (com/net) responses to obtain thick data (default false, to stay polite with registrar rate limits).
func WithTimeout ¶
WithTimeout sets the per-request network timeout (default 10s).
func WithWhoisFallback ¶
WithWhoisFallback toggles falling back to the WHOIS protocol when RDAP is unavailable for the TLD or fails (default true).
func WithWhoisServer ¶
WithWhoisServer pins the WHOIS server used for a given TLD (e.g. WithWhoisServer("example", "127.0.0.1:1043") for tests).
type ParsedInfo ¶
type ParsedInfo struct {
DomainName string
Handle string // registry domain ID / ROID
Registrar string
RegistrarID string // IANA registrar ID
WhoisServer string // port-43 server advertised by the registry
Created *time.Time
Updated *time.Time
Expiry *time.Time
Statuses []string
NameServers []string
DNSSec string
Registrant Contact
Admin Contact
Tech Contact
Billing Contact
// Extra contains every parsed key/value pair (WHOIS source only),
// keyed by lower-cased field name.
Extra map[string][]string
}
ParsedInfo is the normalized registration data shared by RDAP and WHOIS responses. Any field may be empty when the registry does not publish it.
func Parse ¶
func Parse(tld, raw string) (*ParsedInfo, bool)
Parse converts a raw WHOIS response for tld into a ParsedInfo and reports whether the domain appears to be registered. Parsing is best-effort: registries use wildly different formats, so a generic key/value parser is combined with per-TLD rules.
type Record ¶
type Record struct {
// Domain is the queried domain, normalized to its A-label form.
Domain string
// Source tells whether RDAP or the raw WHOIS protocol answered.
Source Source
// Server is the authoritative server that produced the final answer
// (host name of the RDAP server, or the WHOIS server).
Server string
// Registered is false when the registry reports the domain as available.
Registered bool
// Raw is the raw response body (JSON for RDAP, plain text for WHOIS).
// When a WHOIS referral was followed, this is the referral (thick) response.
Raw string
// RegistryRaw holds the original thin-registry WHOIS response when a
// referral was followed; empty otherwise.
RegistryRaw string
// Parsed is a best-effort structured view of Raw.
Parsed *ParsedInfo
}
Record is the result of a successful Query.