dnslookupapi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 11 Imported by: 0

README

dns-lookup-go license dns-lookup-go made-with-Go dns-lookup-go test

Overview

The client library for DNS Lookup API in Go language.

The minimum go version is 1.17.

Installation

The library is distributed as a Go module

go get github.com/whois-api-llc/dns-lookup-go

Examples

Full API documentation available here

You can find all examples in example directory.

Create a new client

To start making requests you need the API Key. You can find it on your profile page on whoisxmlapi.com. Using the API Key you can create Client.

Most users will be fine with NewBasicClient function.

client := dnslookupapi.NewBasicClient(apiKey)

If you want to set custom http.Client to use proxy then you can use NewClient function.

transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

client := dnslookupapi.NewClient(apiKey, dnslookupapi.ClientParams{
    HTTPClient: &http.Client{
        Transport: transport,
        Timeout:   20 * time.Second,
    },
})

Make basic requests

DNS Lookup API lets you get well-structured a domain’s corresponding IP address from its A record as well as the domain’s mail server (MX record), nameserver (NS record), SPF (TXT record), and more records.


// Make request to get all parsed DNS records for the domain name
dnsLookupResp, resp, err := client.Get(ctx, "whoisxmlapi.com")
if err != nil {
    log.Fatal(err)
}

for _, record := range dnsLookupResp.DNSRecords.A {
    log.Println(record.Name)
    log.Println(record.Address)
}

// Make request to get raw DNS Lookup API data
resp, err := client.GetRaw(context.Background(), "whoisxmlapi.com")
if err != nil {
    log.Fatal(err)
}

log.Println(string(resp.Body))


Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedDNSType = errors.New("unknown DNS type")

Functions

This section is empty.

Types

type AAAARecord

type AAAARecord struct {

	// Address is the IPv6 address.
	Address string `json:"address"`
	// contains filtered or unexported fields
}

type ARecord

type ARecord struct {

	// Address is the IPv4 address.
	Address string `json:"address"`
	// contains filtered or unexported fields
}

type ArgError

type ArgError struct {
	Name    string
	Message string
}

ArgError is the argument error.

func (*ArgError) Error

func (a *ArgError) Error() string

Error returns error message as a string.

type Audit

type Audit struct {
	// CreatedDate is the date the DNS records are collected on whoisxmlapi.com
	CreatedDate Time `json:"createdDate"`

	// UpdatedDate is the date the DNS records updated on whoisxmlapi.com
	UpdatedDate Time `json:"updatedDate"`
}

Audit is a part of the DNS Lookup API response It represents dates when Whois record was collected and updated in our database

type CAARecord

type CAARecord struct {

	// Flags is the flag byte.
	Flags int `json:"flags"`

	// Tag is the property identifier.
	Tag string `json:"tag"`

	// Value is a sequence of octets representing the property value.
	Value string `json:"value"`
	// contains filtered or unexported fields
}

type CNAMERecord

type CNAMERecord struct {

	// Alias is an alias for a domain name.
	Alias string `json:"alias"`

	// Target is the target domain name.
	Target string `json:"target"`
	// contains filtered or unexported fields
}

type Client

type Client struct {

	// DNSLookupService is an interface for DNS Lookup API
	DNSLookupService
	// contains filtered or unexported fields
}

Client is the client for DNS Lookup API services.

func NewBasicClient

func NewBasicClient(apiKey string) *Client

NewBasicClient creates Client with recommended parameters.

func NewClient

func NewClient(apiKey string, params ClientParams) *Client

NewClient creates Client with specified parameters.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v io.Writer) (response *http.Response, err error)

Do sends the API request and returns the API response.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, u *url.URL, body io.Reader) (*http.Request, error)

NewRequest creates a basic API request.

type ClientParams

type ClientParams struct {
	// HTTPClient is the client used to access API endpoint
	// If it's nil then value API client uses http.DefaultClient
	HTTPClient *http.Client

	// DNSLookupBaseURL is the endpoint for 'DNS Lookup API' service
	DNSLookupBaseURL *url.URL
}

ClientParams is used to create Client. None of parameters are mandatory and leaving this struct empty works just fine for most cases.

type DHCIDRecord

type DHCIDRecord struct {

	// Data is several octets of binary data.
	Data []string `json:"data"`
	// contains filtered or unexported fields
}

type DLVRecord

type DLVRecord struct {

	// Algorithm lists the algorithm number of the DNSKEY RR.
	Algorithm int `json:"algorithm"`

	// Digest is the digest of a DNSKEY RR.
	Digest []string `json:"digest"`

	// DigestID identifies the algorithm used to construct the digest.
	DigestID int `json:"digestID"`

	// Footprint lists the key tag of the DNSKEY RR.
	Footprint int `json:"footprint"`
	// contains filtered or unexported fields
}

type DNAMERecord

type DNAMERecord struct {

	// Alias is an alias for a domain name.
	Alias string `json:"alias"`

	// Target is the target domain name.
	Target string `json:"target"`
	// contains filtered or unexported fields
}

type DNSKEYRecord

type DNSKEYRecord struct {

	// Algorithm is the public key's cryptographic algorithm.
	Algorithm int `json:"algorithm"`

	// Flags is the Zone Key flag.
	Flags int `json:"flags"`

	// Footprint is the key ID/tag/footprint.
	Footprint int `json:"footprint"`

	// Key holds the public key material.
	Key []string `json:"key"`

	// Protocol is the protocol identifier.
	Protocol int `json:"protocol"`

	// PublicKey is the public key description.
	PublicKey string `json:"publicKey"`
	// contains filtered or unexported fields
}

type DNSLookupResponse

type DNSLookupResponse struct {
	// DomainName is a domain name.
	DomainName string `json:"domainName"`

	// Types are codes of the requested DNS record types.
	Types []int `json:"types"`

	// DNSTypes is the comma-separated list of DNS record types.
	DNSTypes string `json:"dnsTypes"`

	// Audit is a part of the DNS Lookup API response
	// It represents dates when Whois record was collected and updated in our database
	Audit Audit `json:"audit"`

	// DNSRecords is the struct where returned DNS records are stored.
	DNSRecords DNSRecords `json:"dnsRecords"`
}

DNSLookupResponse is a response of DNS Lookup API.

type DNSLookupService

type DNSLookupService interface {
	// Get returns parsed DNS Lookup API response
	Get(ctx context.Context, domainName string, opts ...Option) (*DNSLookupResponse, *Response, error)

	// GetRaw returns raw DNS Lookup API response as Response struct with Body saved as a byte slice
	GetRaw(ctx context.Context, domainName string, opts ...Option) (*Response, error)
}

DNSLookupService is an interface for DNS Lookup API.

type DNSRecord

type DNSRecord struct {
	CommonFields commonFields

	// Raw is a not parsed DNS record.
	Raw json.RawMessage `json:"raw"`

	// ParseError is the error that occurred during parsing.
	ParseError error `json:"parseError"`
}

type DNSRecords

type DNSRecords struct {
	// All is a slice of all parsed DNS records.
	All []DNSRecord

	// A is a slice of the parsed A records.
	A []ARecord

	// AAAA is a slice of the parsed AAAA records.
	AAAA []AAAARecord

	// NS is a slice of the parsed NS records.
	NS []NSRecord

	// MX is a slice of the parsed MX records.
	MX []MXRecord

	// MD is a slice of the parsed MD records.
	MD []MDRecord

	// MF is a slice of the parsed MF records.
	MF []MFRecord

	// MB is a slice of the parsed MF records.
	MB []MBRecord

	// SOA is a slice of the parsed SOA records.
	SOA []SOARecord

	// TXT is a slice of the parsed TXT records.
	TXT []TXTRecord

	// CAA is a slice of the parsed CAA records.
	CAA []CAARecord

	// CNAME is a slice of the parsed CNAME records.
	CNAME []CNAMERecord

	// DNAME is a slice of the parsed CNAME records.
	DNAME []DNAMERecord

	// DNSKEY is a slice of the parsed DNSKEY records.
	DNSKEY []DNSKEYRecord

	// NSEC3PARAM is a slice of the parsed NSEC3PARAM records.
	NSEC3PARAM []NSEC3PARAMRecord

	// NSEC is a slice of the parsed NSEC records.
	NSEC []NSECRecord

	// DS is a slice of the parsed DS records.
	DS []DSRecord

	// PTR is a slice of the parsed PTR records.
	PTR []PTRRecord

	// SRV is a slice of the parsed SRV records.
	SRV []SRVRecord

	// LOC is a slice of the parsed LOC records.
	LOC []LOCRecord

	// NAPTR is a slice of the parsed NAPTR records.
	NAPTR []NAPTRRecord

	// HINFO is a slice of the parsed HINFO records.
	HINFO []HINFORecord

	// RP is a slice of the parsed RP records.
	RP []RPRecord

	// DLV is a slice of the parsed DLV records.
	DLV []DLVRecord

	// SSHFP is a slice of the parsed SSHFP records.
	SSHFP []SSHFPRecord

	// TLSA is a slice of the parsed TLSA records.
	TLSA []TLSARecord

	// DHCID is a slice of the parsed DHCID records.
	DHCID []DHCIDRecord

	// NSAP is a slice of the parsed NSAP records.
	NSAP []NSAPRecord

	// NULL is a slice of the parsed NULL records.
	NULL []NULLRecord
}

DNSRecords is the struct where returned DNS records are stored.

func (*DNSRecords) MarshalJSON

func (r *DNSRecords) MarshalJSON() ([]byte, error)

MarshalJSON encodes DNSRecords.

func (*DNSRecords) UnmarshalJSON

func (r *DNSRecords) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes DNS records and returns them as a DNSRecords struct.

type DSRecord

type DSRecord struct {

	// Algorithm lists the algorithm number of the DNSKEY RR.
	Algorithm int `json:"algorithm"`

	// Digest is the digest of a DNSKEY RR.
	Digest []string `json:"digest"`

	// DigestID identifies the algorithm used to construct the digest.
	DigestID int `json:"digestID"`

	// Footprint lists the key tag of the DNSKEY RR.
	Footprint int `json:"footprint"`
	// contains filtered or unexported fields
}

type ErrorMessage

type ErrorMessage struct {
	Code    string `json:"errorCode"`
	Message string `json:"msg"`
}

ErrorMessage is an error message.

func (*ErrorMessage) Error

func (e *ErrorMessage) Error() string

Error returns error message as a string.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Message  string
}

ErrorResponse is returned when the response status code is not 2xx.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error returns error message as a string.

type HINFORecord

type HINFORecord struct {

	// CPU specifies the CPU type.
	CPU string `json:"cpu"`

	// OS specifies the operating system type.
	OS string `json:"os"`
	// contains filtered or unexported fields
}

type LOCRecord

type LOCRecord struct {

	// Altitude is the altitude of the center of the sphere described by the Size field.
	Altitude float64 `json:"altitude"`

	// HPrecision is the horizontal precision of the data, in centimeters.
	HPrecision float64 `json:"hPrecision"`

	// Latitude is the latitude of the center of the sphere described by the Size field.
	Latitude float64 `json:"latitude"`

	// Longitude is the longitude of the center of the sphere described by the Size field.
	Longitude float64 `json:"longitude"`

	// Size is the diameter of a sphere enclosing the described entity.
	Size float64 `json:"size"`

	// VPrecision is the vertical precision of the data, in centimeters.
	VPrecision float64 `json:"vPrecision"`
	// contains filtered or unexported fields
}

type MBRecord

type MBRecord struct {

	// AdditionalName is a compressed domain name which specifies a host which has the specified mailbox.
	AdditionalName string `json:"additionalName"`

	// Mailbox is a compressed domain name which specifies a host which has the specified mailbox.
	Mailbox string `json:"mailbox"`
	// contains filtered or unexported fields
}

type MDRecord

type MDRecord struct {

	// AdditionalName is a compressed domain name which specifies a host which has a mail agent for the domain.
	AdditionalName string `json:"additionalName"`

	// MailAgent is a compressed domain name which specifies a host which has a mail agent for the domain.
	MailAgent string `json:"mailAgent"`
	// contains filtered or unexported fields
}

type MFRecord

type MFRecord struct {

	// AdditionalName is a compressed domain name which specifies a host which has a mail agent for the domain.
	AdditionalName string `json:"additionalName"`

	// MailAgent is a compressed domain name which specifies a host which has a mail agent for the domain.
	MailAgent string `json:"mailAgent"`
	// contains filtered or unexported fields
}

type MXRecord

type MXRecord struct {

	// Target is the domain name of a mail server.
	Target string `json:"target"`

	// Priority is the priority field.
	Priority int `json:"priority"`
	// contains filtered or unexported fields
}

type NAPTRRecord

type NAPTRRecord struct {

	// Flags are flags to control aspects of the rewriting and interpretation of the fields in the record
	// as part of NAPTR record.
	Flags string `json:"flags"`

	// Order is a 16-bit unsigned integer specifying the order in which the NAPTR records MUST be processed.
	Order int `json:"order"`

	// Preference is a 16-bit unsigned integer that specifies the order in which NAPTR records with equal Order values
	// SHOULD be processed.
	Preference int `json:"preference"`

	// Regexp contains a substitution expression that is applied to the original string held by the client.
	Regexp string `json:"regexp"`

	// Replacement is a domain name which is the next domain-name to query for
	// depending on the potential values found in the flags field.
	Replacement string `json:"replacement"`

	// Service specifies the Service Parameters applicable to the delegation path.
	Service string `json:"service"`
	// contains filtered or unexported fields
}

type NSAPRecord

type NSAPRecord struct {

	// Address is a variable length string of octets containing the NSAP.
	Address string `json:"address"`
	// contains filtered or unexported fields
}

type NSEC3PARAMRecord

type NSEC3PARAMRecord struct {

	// Flags are 8 one-bit flags.
	Flags int `json:"flags"`

	// HashAlgorithm is the cryptographic hash algorithm used to construct the hash-value.
	HashAlgorithm int `json:"hashAlgorithm"`

	// Iterations defines the number of additional times the hash function has been performed.
	Iterations int `json:"iterations"`

	// Salt is a value which appended to the original owner name before hashing.
	Salt []string `json:"salt"`
	// contains filtered or unexported fields
}

type NSECRecord

type NSECRecord struct {

	// Next contains the next hashed owner name in hash order.
	Next string `json:"next"`

	// Types is the type bit maps.
	Types []int `json:"types"`
	// contains filtered or unexported fields
}

type NSRecord

type NSRecord struct {

	// Target is the name server.
	Target string `json:"target"`
	// contains filtered or unexported fields
}

type NULLRecord

type NULLRecord struct {

	// Data is anything, so long as it is 65535 octets or less.
	Data []string `json:"data"`
	// contains filtered or unexported fields
}

type Option

type Option func(v url.Values)

Option adds parameters to the query.

func OptionCallback

func OptionCallback(value string) Option

OptionCallback sets a javascript function used when outputFormat is JSON; this is an implementation known as JSONP which invokes the callback on the returned response.

func OptionOutputFormat

func OptionOutputFormat(outputFormat string) Option

OptionOutputFormat sets Response output format JSON | XML. Default: JSON.

func OptionType

func OptionType(value string) Option

OptionType sets types of DNS records that should be returned. DNS type: A, NS, SOA, MX, etc. You can specify multiple comma-separated values, e.g., A,SOA,TXT; all records can be retrieved with type=_all (by default).

type PTRRecord

type PTRRecord struct {

	// Target is a domain name.
	Target string `json:"target"`
	// contains filtered or unexported fields
}

type RPRecord

type RPRecord struct {

	// Mailbox is a domain name that specifies the mailbox for the responsible person.
	Mailbox string `json:"mailbox"`

	// TextDomain is a domain name for which TXT RR's exist.
	TextDomain string `json:"textDomain"`
	// contains filtered or unexported fields
}

type Response

type Response struct {
	*http.Response

	// Body is the byte slice representation of http.Response Body
	Body []byte
}

Response is the http.Response wrapper with Body saved as a byte slice.

type SOARecord

type SOARecord struct {

	// Admin is the email address of the administrator.
	Admin string `json:"admin"`

	// Host is the primary master name server.
	Host string `json:"host"`

	// Expire is the number of seconds after which secondary name servers should stop answering request
	// if the master does not respond.
	Expire int `json:"expire"`

	// Minimum is the negative response caching TTL.
	Minimum int `json:"minimum"`

	// Refresh is the number of seconds after which secondary name servers should query the master for the SOA record,
	// to detect zone changes.
	Refresh int `json:"refresh"`

	// Retry is the number of seconds after which secondary name servers should retry to request the serial number
	// from the master if the master does not respond.
	Retry int `json:"retry"`

	// Serial is the serial number.
	Serial int `json:"serial"`
	// contains filtered or unexported fields
}

type SRVRecord

type SRVRecord struct {

	// Port is the port on the target host of the service.
	Port int `json:"port"`

	// Priority is the priority of the target host.
	Priority int `json:"priority"`

	// Target is the domain name of the target host.
	Target string `json:"target"`

	// Weight is a server selection mechanism.
	Weight int `json:"weight"`
	// contains filtered or unexported fields
}

type SSHFPRecord

type SSHFPRecord struct {

	// Algorithm describes the algorithm of the public key.
	Algorithm int `json:"algorithm"`

	// DigestType describes the message-digest algorithm used to calculate the fingerprint of the public key.
	DigestType int `json:"digestType"`

	// FingerPrint is calculated over the public key blob.
	FingerPrint []string `json:"fingerPrint"`
	// contains filtered or unexported fields
}

type TLSARecord

type TLSARecord struct {

	// CertificateAssociationData specifies the "certificate association data" to be matched.
	CertificateAssociationData []string `json:"certificateAssociationData"`

	// CertificateUsage specifies the provided association that will be used to match the certificate
	// presented in the TLS handshake.
	CertificateUsage int `json:"certificateUsage"`

	// MatchingType specifies how the certificate association is presented.
	MatchingType int `json:"matchingType"`

	// Selector specifies which part of the TLS certificate presented by the server will be matched against
	// the association data.
	Selector int `json:"selector"`
	// contains filtered or unexported fields
}

type TXTRecord

type TXTRecord struct {

	// Strings is the slice of text strings as part of the TXT record.
	Strings []string `json:"strings"`
	// contains filtered or unexported fields
}

type Time

type Time time.Time

Time is a helper wrapper on time.Time.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON encodes time as DNS Lookup API does.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes time as DNS Lookup API does.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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