whois

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 10 Imported by: 0

README

WHOIS Client

a simple Go WHOIS Client API.

How it works

  • split domain name and finds corresponded WHOIS DB server from db.yaml.
  • dial a connection to the WHOIS server.
  • save the response.

whois.NewClient function takes a Dailer argument.

// Dialer
type Dialer interface {
    DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

using a nil arg to whois.NewClient will create a client using local connect.

Tracking

Install

go get github.com/twiny/whois-go

Example

  • using local connection
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/twiny/whois-go"
)

func main() {
	client, err := whois.NewClient(nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	text, err := client.Lookup(ctx, "google.com")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(text)
	fmt.Println("done.")
}
  • using SOCKS5 connection
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/twiny/whois-go"
	"golang.org/x/net/proxy"
)

func main() {
	// create default client
	client, err := whois.NewClient(nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	// using SOCKS5
	// auth if required
	auth := &proxy.Auth{
		User:     "username",
		Password: "password",
	}
	dialer, err := proxy.SOCKS5("tcp", "hostname:port", auth, proxy.Direct)
	if err != nil {
		fmt.Println(err)
		return
	}

	// clone default client
	proxyClient, err := client.Clone(dialer)
	if err != nil {
		fmt.Println(err)
		return
	}

	// ctx
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	text, err := proxyClient.Lookup(ctx, "google.com")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(text)
	fmt.Println("done.")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyResponse    = errors.New("empty whois response")
	ErrBadDialer        = errors.New("bad dialer")
	ErrConnectionFailed = errors.New("could not establish connection")
	ErrTimeout          = errors.New("timeout")
)

Errors

View Source
var (
	ErrDBServerEmpty     = errors.New("empty whois server database")
	ErrWHOISHostNotFound = errors.New("whois host not found")
)

Errors

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client

func NewClient

func NewClient(dialer Dialer) (*Client, error)

NewClient

func (*Client) Clone

func (c *Client) Clone(dialer interface{}) (*Client, error)

Clone

func (*Client) Hosts

func (c *Client) Hosts() []string

Hosts

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, domain string) (string, error)

Lookup

func (*Client) LookupHost

func (c *Client) LookupHost(ctx context.Context, domain, host string) (string, error)

LookupHost

func (*Client) Split

func (c *Client) Split(domain string) (name, tld, host string, err error)

Split

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer

Jump to

Keyboard shortcuts

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