whois

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: Apache-2.0 Imports: 4 Imported by: 2

README

whois

test

Lightweight library for retrieving WHOIS information on a domain.

It automatically retrieves the appropriate WHOIS server based on the domain's TLD by first querying IANA.

Usage

As an executable

To install it:

go install github.com/TwiN/whois/cmd/whois@latest

To run it:

whois example.com
As a library
go get github.com/TwiN/whois
Query

If all you want is the text a WHOIS server would return you, you can use the Query method of the whois.Client type:

package main

import "github.com/TwiN/whois"

func main() {
    client := whois.NewClient()
    output, err := client.Query("example.com")
    if err != nil {
    	panic(err)
    }
    println(output)
}
QueryAndParse

If you want specific pieces of information, you can use the QueryAndParse method of the whois.Client type:

package main

import "github.com/TwiN/whois"

func main() {
    client := whois.NewClient()
    response, err := client.QueryAndParse("example.com")
    if err != nil {
    	panic(err)
    }
    println(response.ExpirationDate.String()) 
}

Note that because there is no standardized format for WHOIS responses, this parsing may not be successful for every single TLD.

Currently, the only fields parsed are:

  • ExpirationDate: The time.Time at which the domain will expire
  • DomainStatuses: The statuses that the domain currently has (e.g. clientTransferProhibited)
  • NameServers: The nameservers currently tied to the domain

If you'd like one or more other fields to be parsed, please don't be shy and create an issue or a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient() *Client

func (Client) Query

func (c Client) Query(domain string) (string, error)

func (Client) QueryAndParse

func (c Client) QueryAndParse(domain string) (*Response, error)

QueryAndParse tries to parse the response from the WHOIS server There is no standardized format for WHOIS responses, so this is an attempt at best.

Being the selfish person that I am, I also only parse the fields that I need. If you need more fields, please open an issue or pull request.

type Response

type Response struct {
	ExpirationDate time.Time
	DomainStatuses []string
	NameServers    []string
}

Directories

Path Synopsis
cmd
whois command

Jump to

Keyboard shortcuts

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