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).
Beyond domains, QueryIP looks up IPv4/IPv6 registrations (RDAP via the five RIRs, with a whois.iana.org-referred WHOIS fallback) and QueryASN looks up autonomous system numbers (RDAP only).
Usage:
c := whois.New()
rec, err := c.Query("example.com")
if err != nil { ... }
fmt.Println(rec.Source, rec.Registered, rec.Parsed.Expiry)
ip, err := c.QueryIP("8.8.8.8")
asn, err := c.QueryASN(15169)
The zero-dependency package also exposes Parse and ParseIPWhois (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 ASNInfo
- type ASNRecord
- type Client
- func (c *Client) Query(domain string) (*Record, error)
- func (c *Client) QueryASN(asn uint32) (*ASNRecord, error)
- func (c *Client) QueryASNContext(ctx context.Context, asn uint32) (*ASNRecord, error)
- func (c *Client) QueryContext(ctx context.Context, domain string) (*Record, error)
- func (c *Client) QueryIP(ip string) (*IPRecord, error)
- func (c *Client) QueryIPContext(ctx context.Context, ip string) (*IPRecord, error)
- type Contact
- type EntityContact
- type IPInfo
- type IPRecord
- 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 ASNInfo ¶ added in v0.2.0
type ASNInfo struct {
Handle string
Name string
Type string
Country string
StartAutnum uint32
EndAutnum uint32
Statuses []string
Created *time.Time
Updated *time.Time
Entities []EntityContact
}
ASNInfo is a normalized view of an autnum registration.
type ASNRecord ¶ added in v0.2.0
type ASNRecord struct {
Query uint32
Source Source
Server string
Found bool
Raw string
Parsed *ASNInfo
}
ASNRecord is the result of a QueryASN lookup.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client queries domain registration data. It is safe for concurrent use.
func (*Client) Query ¶
Query looks up domain: RDAP first (via rdap.org bootstrap), falling back to the raw WHOIS protocol for TLDs without RDAP deployment.
func (*Client) QueryASN ¶ added in v0.2.0
QueryASN looks up an autonomous system number. RDAP covers every allocated ASN via the IANA bootstrap, so no WHOIS fallback is needed.
func (*Client) QueryASNContext ¶ added in v0.2.0
QueryASNContext is QueryASN with a context.
func (*Client) QueryContext ¶
QueryContext is Query with a context.
type EntityContact ¶ added in v0.2.0
EntityContact associates registry roles with contact data.
type IPInfo ¶ added in v0.2.0
type IPInfo struct {
Handle string
Name string
Type string // e.g. "DIRECT ALLOCATION", "ASSIGNED PA"
StartAddress string
EndAddress string
CIDR string
Version string // "v4" or "v6" (RDAP only)
Country string
ParentHandle string
Statuses []string
Created *time.Time
Updated *time.Time
Organization string
Description string
Entities []EntityContact
}
IPInfo is a normalized view of an IP network registration (RDAP "ip network" object or an RIR WHOIS response).
func ParseIPWhois ¶ added in v0.2.0
ParseIPWhois converts a raw RIR WHOIS response into an IPInfo and reports whether the address block is registered.
type IPRecord ¶ added in v0.2.0
type IPRecord struct {
// Query is the queried IP address in canonical form.
Query string
// Source tells whether RDAP or the raw WHOIS protocol answered.
Source Source
// Server is the RIR server that produced the final answer.
Server string
// Found is false when the RIR reports no registration for the address.
Found bool
// Raw is the raw response body (JSON for RDAP, plain text for WHOIS).
Raw string
// Parsed is a best-effort structured view of Raw.
Parsed *IPInfo
}
IPRecord is the result of a QueryIP lookup.
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.