Documentation ¶
Index ¶
- Constants
- Variables
- func FmtWhoisServer(host string, port int) string
- func IsParsePanicErr(err error) bool
- func StartMockWhoisServer(addr string, handlers ...func(net.Conn)) (net.Listener, error)
- func StartTCPServer(addr string, handler func(net.Conn)) (net.Listener, error)
- type Client
- func (c *Client) Parse(ps string, wrt *Raw) (pw *wd.Whois, err error)
- func (c *Client) ParseIP(ip string, wrt *Raw) (pip *wip.Whois, err error)
- func (c *Client) Query(ctx context.Context, domain string, whoisServer ...string) (*wd.Whois, error)
- func (c *Client) QueryIP(ctx context.Context, ip string, whoisServers ...string) (*wip.Whois, error)
- func (c *Client) QueryIPChan(status *Status) chan *wip.Whois
- func (c *Client) QueryIPRaw(ctx context.Context, ip, whoisServer string) (*Raw, error)
- func (c *Client) QueryPublicSuffix(ctx context.Context, ps string, whoisServer ...string) (*wd.Whois, error)
- func (c *Client) QueryPublicSuffixs(ctx context.Context, pslist []string, whoisServer ...string) (*wd.Whois, error)
- func (c *Client) QueryPublicSuffixsChan(status *Status) chan *wd.Whois
- func (c *Client) QueryRaw(ctx context.Context, ps string, whoisServer ...string) (*Raw, error)
- type ClientOpts
- func WithARIN(arinAddr string) ClientOpts
- func WithErrLogger(logger logrus.FieldLogger) ClientOpts
- func WithIANA(ianaAddr string) ClientOpts
- func WithServerMap(serverMap DomainWhoisServerMap) ClientOpts
- func WithTestingWhoisPort(port int) ClientOpts
- func WithTimeout(timeout time.Duration) ClientOpts
- type DomainList
- type DomainWhoisServerMap
- type Raw
- type Status
- type WhoisServer
Constants ¶
const ( // Values of RespType RespTypeFound = "found" RespTypeNotFound = "not_found" RespTypeParseError = "parse_error" RespTypeError = "error" RespTypeTimeout = "timeout" // Values of AccType TypeDomain = "domain" TypeIP = "ip" DefaultIANAWhoisServer = "whois.iana.org" DefaultWhoisPort = 43 )
const WhoisServerListURL = "http://whois-server-list.github.io/whois-server-list/3.0/whois-server-list.xml"
WhoisServerListURL maps tlds to corresponding whois server list
Variables ¶
var ( DefaultReadTimeout = 5 * time.Second DefaultWriteTimeout = 5 * time.Second DefaultTimeout = 5 * time.Second DefaultIPWhoisServerMap = map[string]string{ "APNIC": "whois.apnic.net", "ARIN": "whois.arin.net", "RIPE": "whois.ripe.net", "LACNIC": "whois.lacnic.net", "AFRINIC": "whois.afrinic.net", } DefaultIANA = FmtWhoisServer(DefaultIANAWhoisServer, DefaultWhoisPort) DefaultARIN = FmtWhoisServer("whois.arin.net", DefaultWhoisPort) // ErrDomainIPNotFound is fixed error message for WHOIS not found ErrDomainIPNotFound = errors.New("domain/ip not found") // ErrTimeout is fixed error message for timeout quering WHOIS server ErrTimeout = errors.New("timeout") )
var ( TestTimeoutDomain = "timeout.aaa" TestTimeoutIP = "85.34.28.46" TestNotFoundDomain = "abc.app" TestDomain = "github.io" TestDomainWhoisRawText = `` /* 1563-byte string literal not displayed */ TestNotFoundIP = "80.20.14.56" TestIP = "20.11.10.87" TestIPWhoisRawText = `` /* 1683-byte string literal not displayed */ )
Functions ¶
func FmtWhoisServer ¶
FmtWhoisServer concate host and port to query whois
func IsParsePanicErr ¶
func StartMockWhoisServer ¶
StartMockWhoisServer starts mock whois server for testing
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to query whois server to get latest whois information
func NewClient ¶
func NewClient(opts ...ClientOpts) (*Client, error)
NewClient initializes whois client with different options, if whois server map is not given it will fetch from http://whois-server-list.github.io/whois-server-list/3.0/whois-server-list.xml
func (*Client) Parse ¶
Parse get parser based on TLD and use it to parse rawtext. Also check if rawtext contains **not found** keywords
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, domain string, whoisServer ...string) (*wd.Whois, error)
Query get whois information from given whois server or predefined whois server map with domain
func (*Client) QueryIP ¶
func (c *Client) QueryIP(ctx context.Context, ip string, whoisServers ...string) (*wip.Whois, error)
QueryIP get whois information from given whois server or query 'whois.arin.net' and parse 'OrgId' to get the organization and map to the whois server, query again if it's not 'whois.arin.net'
func (*Client) QueryIPChan ¶
QueryIPChan performs query and returns channel for caller to wait for the result
func (*Client) QueryIPRaw ¶
QueryIPRaw query whois server with IP
func (*Client) QueryPublicSuffix ¶
func (c *Client) QueryPublicSuffix(ctx context.Context, ps string, whoisServer ...string) (*wd.Whois, error)
QueryPublicSuffix get whois information from given whois server or predefined whois server map with public suffix
func (*Client) QueryPublicSuffixs ¶
func (c *Client) QueryPublicSuffixs(ctx context.Context, pslist []string, whoisServer ...string) (*wd.Whois, error)
QueryPublicSuffixs get whois information from given whois server or predefined whois server map with public suffix list
func (*Client) QueryPublicSuffixsChan ¶
QueryPublicSuffixsChan performs query and returns channel for caller to wait for the result
type ClientOpts ¶
func WithARIN ¶
func WithARIN(arinAddr string) ClientOpts
func WithErrLogger ¶
func WithErrLogger(logger logrus.FieldLogger) ClientOpts
func WithIANA ¶
func WithIANA(ianaAddr string) ClientOpts
func WithServerMap ¶
func WithServerMap(serverMap DomainWhoisServerMap) ClientOpts
func WithTestingWhoisPort ¶
func WithTestingWhoisPort(port int) ClientOpts
WithTestingWhoisPort is expected to only use in testing since whois port is 43
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOpts
type DomainList ¶
type DomainList struct { XMLName xml.Name `xml:"domainList"` Text string `xml:",chardata"` Version string `xml:"version,attr"` Date string `xml:"date"` Description string `xml:"description"` Domain []struct { Text string `xml:",chardata"` Name string `xml:"name,attr"` Source string `xml:"source"` Created string `xml:"created"` Changed string `xml:"changed"` RegistrationService string `xml:"registrationService"` State string `xml:"state"` WhoisServer []struct { Text string `xml:",chardata"` Host string `xml:"host,attr"` Source string `xml:"source"` AvailablePattern string `xml:"availablePattern"` ErrorPattern string `xml:"errorPattern"` QueryFormat string `xml:"queryFormat"` } `xml:"whoisServer"` CountryCode string `xml:"countryCode"` Domain []struct { Text string `xml:",chardata"` Name string `xml:"name,attr"` Source string `xml:"source"` WhoisServer []struct { Text string `xml:",chardata"` Host string `xml:"host,attr"` Source string `xml:"source"` AvailablePattern string `xml:"availablePattern"` ErrorPattern string `xml:"errorPattern"` QueryFormat string `xml:"queryFormat"` } `xml:"whoisServer"` } `xml:"domain"` } `xml:"domain"` }
DomainList is generated by https://www.onlinetool.io/xmltogo/ parse xml URL: // ref. http://whois-server-list.github.io/whois-server-list/3.0/whois-server-list.xml
type DomainWhoisServerMap ¶
type DomainWhoisServerMap map[string][]WhoisServer
DomainWhoisServerMap stores tld and it's whois server list key: tld val: list of whoisServer
func NewDomainWhoisServerMap ¶
func NewDomainWhoisServerMap(xmlpath string) (DomainWhoisServerMap, error)
NewDomainWhoisServerMap initialize map from 'xmlpath' support local file path and file from web
func (DomainWhoisServerMap) GetWhoisServer ¶
func (dsmap DomainWhoisServerMap) GetWhoisServer(ps string) []WhoisServer
GetWhoisServer get whois server list given public suffix Example:
ps="pooch.co.uk", search order: "pooch.co.uk" -> "co.uk" -> "uk" ps="co.uk", search order: "co.uk" -> "uk"
type Raw ¶
type Raw struct { Rawtext string Server string // whois server that response the raw text Avail *bool }
Raw records rawtext from whois server
type Status ¶
type Status struct { DomainOrIP string PublicSuffixs []string WhoisServer string RespType string Err error }
Status records response status for query