whois

package
v0.0.0-...-013418f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

View Source
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")
)
View Source
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

func FmtWhoisServer(host string, port int) string

FmtWhoisServer concate host and port to query whois

func IsParsePanicErr

func IsParsePanicErr(err error) bool

func StartMockWhoisServer

func StartMockWhoisServer(addr string, handlers ...func(net.Conn)) (net.Listener, error)

StartMockWhoisServer starts mock whois server for testing

func StartTCPServer

func StartTCPServer(addr string, handler func(net.Conn)) (net.Listener, error)

StartTCPServer is used to start mock WHOIS TCP server

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

func (c *Client) Parse(ps string, wrt *Raw) (pw *wd.Whois, err error)

Parse get parser based on TLD and use it to parse rawtext. Also check if rawtext contains **not found** keywords

func (*Client) ParseIP

func (c *Client) ParseIP(ip string, wrt *Raw) (pip *wip.Whois, err error)

ParseIP get parser and parse rawtext

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

func (c *Client) QueryIPChan(status *Status) chan *wip.Whois

QueryIPChan performs query and returns channel for caller to wait for the result

func (*Client) QueryIPRaw

func (c *Client) QueryIPRaw(ctx context.Context, ip, whoisServer string) (*Raw, error)

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

func (c *Client) QueryPublicSuffixsChan(status *Status) chan *wd.Whois

QueryPublicSuffixsChan performs query and returns channel for caller to wait for the result

func (*Client) QueryRaw

func (c *Client) QueryRaw(ctx context.Context, ps string, whoisServer ...string) (*Raw, error)

QueryRaw query whois server with public suffix

type ClientOpts

type ClientOpts func(*Client) error

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

func NewRaw

func NewRaw(rawtext, server string, availPtn ...*regexp.Regexp) *Raw

type Status

type Status struct {
	DomainOrIP    string
	PublicSuffixs []string
	WhoisServer   string
	RespType      string
	Err           error
}

Status records response status for query

func NewStatus

func NewStatus(ws string) *Status

type WhoisServer

type WhoisServer struct {
	Host     string
	AvailPtn *regexp.Regexp // pattern to check if domain is available
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL