whois

package module
v2.0.0-...-a5fbbcc Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 14 Imported by: 1

README

WHOIS Client

a simple Go WHOIS Client API.

API

Lookup(ctx context.Context, domain, server string) (string, error)
WHOISHost(domain string) (string, error)
TLDs() []string

Install

go get github.com/twiny/whois/v2

Example

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/twiny/whois/v2"
)

func main() {
	domain := "google.com"

	// to use Socks5 - this format 'socks5://username:password@alpha.hostname.com:1023'
	// otherwise use 'whois.Localhost' to use local connection
	client, err := whois.NewClient(whois.Localhost)
	if err != nil {
		fmt.Println(err)
		return
	}

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

	host, err := client.WHOISHost(domain)
	if err != nil {
		fmt.Println(err)
		return
	}

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

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

Tracking

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Localhost string = "socks5://localhost" // used for default client

)

Functions

This section is empty.

Types

type Client

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

Client

func NewClient

func NewClient(socks5 string) (*Client, error)

NewClient: a new WHOIS client using a Socks5 connection in this format: socks5://username:password@alpha.hostname.com:1023 to use local connection pass `whois.Localhost` as argument.

func (*Client) Lookup

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

Lookup a domain in a whois server db

func (*Client) TLDs

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

TLDs

func (*Client) WHOISHost

func (c *Client) WHOISHost(domain string) (string, error)

Split domain name into 3 parts name, tld, server or an error

Jump to

Keyboard shortcuts

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