whois

package module
v0.0.0-...-86dd260 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: MIT Imports: 10 Imported by: 0

README

whois - a whois implementation/parser, written in go

Documentation

Examples

Query by URL:

parsedData, err := whois.URL("https://github.com/Myra-Security-GmbH/whois")
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(parsedData.Records()[0].data["city"])
//Output:
//San Francisco

Query by Host/Domain:

parsedData, err := whois.Domain("google.net")
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(parsedData.Records()[0].data["city"])
//Output:
//Mountain View

Query by IP:

parsedData, err := whois.IP(net.ParseIP("194.25.2.129"))
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(parsedData.Records()[1].data["org-name"])
// Output:
// Deutsche Telekom AG

Documentation

Index

Constants

View Source
const (
	// RipeServer used for ip/net queries
	RipeServer = "whois.ripe.net:43"

	// ApnicServer ...
	ApnicServer = "whois.apnic.net:43"

	// ArinServer ...
	ArinServer = "whois.arin.net:43"

	// AfrinicServer ...
	AfrinicServer = "whois.afrinic.net:43"

	// LacnicServer ...
	LacnicServer = "whois.lacnic.net:43"

	// IanaServer ...
	IanaServer = "whois.iana.org:43"

	// DenicServer ...
	DenicServer = "whois.denic.de:43"
)
View Source
const (
	// FormatDenic ...
	FormatDenic = "denic"
	// FormatIana ...
	FormatIana = "iana"
	// FormatRipe ...
	FormatRipe = "ripe"
	// FormatApnic ...
	FormatApnic = "apnic"
	// FormatAfrinic ...
	FormatAfrinic = "afrinic"
	// FormatLacnic ...
	FormatLacnic = "lacnic"
	// FormatArin ...
	FormatArin = "arin"
	// FormatIcaan ...
	FormatIcaan = "icaan"
)
View Source
const (
	// RecordTypeTechC record type for technical
	RecordTypeTechC = 1

	// RecordTypeAdminC record type for admins
	RecordTypeAdminC = 2

	// RecordTypeOwner record type for owner
	RecordTypeOwner = 3

	// RecordTypeNetwork record type for a network
	RecordTypeNetwork = 4

	// RecordTypeDomain record type for a domain
	RecordTypeDomain = 5

	// RecordTypeOther for all other records
	RecordTypeOther = 256
)

Variables

This section is empty.

Functions

func DetermineWhoisServerForIP

func DetermineWhoisServerForIP(ip net.IP) string

DetermineWhoisServerForIP returns the whois server responsible for the given ip network.

func SaveToFile

func SaveToFile(filepath string, cache *KVCache) error

SaveToFile saves the current cache into a file.

Types

type KVCache

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

KVCache a simple key Value structure with ttl.

func LoadFromFile

func LoadFromFile(filepath string) (*KVCache, error)

LoadFromFile restores the cache from a previous saved file.

func NewCache

func NewCache(ttl int) *KVCache

NewCache creates a new KVCache instance.

func (*KVCache) Add

func (c *KVCache) Add(key string, value QueryResult) bool

Add appends an additional key to the current KVCache. If the entry already exist the value and lastUpdate will be updated. Returns true if the key did not exist before otherwise false.

func (*KVCache) Clean

func (c *KVCache) Clean(ttl time.Duration)

Clean removes all entries which are not accassed more than the given time.

func (*KVCache) Get

func (c *KVCache) Get(key string) (result QueryResult, found bool)

Get returns the value for the given key If the key's lastUpdate is older than the ttl allows default/empty is returned

type QueryRecord

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

QueryRecord containing parsed record data and additional meta data

func NewQueryRecord

func NewQueryRecord(data map[string]string, recordType int) QueryRecord

NewQueryRecord creates and returns a new QueryRecord

func (QueryRecord) Data

func (r QueryRecord) Data() map[string]string

Data returns the parsed data map

func (QueryRecord) RecordType

func (r QueryRecord) RecordType() int

RecordType returns the record type

type QueryResult

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

QueryResult contains raw and parsed information of a whois query

func Domain

func Domain(domainOrHost string, cache *KVCache) (result QueryResult, err error)

Domain performs a whois query for the given domain or hostname.

func IP

func IP(ip net.IP, cache *KVCache) (result QueryResult, err error)

IP performs a whois query for the given net.IP.

func NewQueryResult

func NewQueryResult(in []byte) QueryResult

NewQueryResult creates and returns a new QueryResult

func Parse

func Parse(raw []byte, format string) (parsed QueryResult)

Parse the given raw data using a format specific parse function

func URL

func URL(url string, cache *KVCache) (result QueryResult, err error)

URL returns a whois from the domain name of an url.

func (QueryResult) RawOutput

func (q QueryResult) RawOutput() []byte

RawOutput returns the raw output

func (QueryResult) Records

func (q QueryResult) Records() []QueryRecord

Records returns a list of all parsed records.

func (QueryResult) Target

func (q QueryResult) Target() string

Target returns the queried target (hostname or IP)

Jump to

Keyboard shortcuts

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