dnsdb

package module
v0.0.0-...-e31fbd7 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2016 License: MIT Imports: 11 Imported by: 0

README

go-dnsdb GoDoc Build Status Coverage Status

An (Unofficial) Golang client for Farsight Security's DNSDB (https://api.dnsdb.info/)

Usage

import "github.com/bored-engineer/go-dnsdb"

To list all RRSet records matching www.farsightsecurity.com:

records, _, err := client.RRSet.LookupName("www.farsightsecurity.com", nil)
if err != nil {
	panic(err)
}
for _, record := range records {
	fmt.Println("%s: %v", *record.RRName, record.RData)
}

For furthur usage see the GoDocs.

Authentication

The dnsdb library does not directly handle authentication. Instead, when creating a new client, you can pass a http.Client that handles authentication for you. It does provide a APIKeyTransport structure when using API Key authentication. It is used like this:

tp := dnsdb.APIKeyTransport{
	APIKey: "d41d8cd98f00b204e9800998ecf8427e",
}

client := dnsdb.NewClient(tp.Client())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(string string) *string

String allocates a new string value to store and returns a pointer to it.

func Uint64

func Uint64(uint64 uint64) *uint64

UInt64 allocates a new uint64 value to store and returns a pointer to it.

Types

type APIKeyTransport

type APIKeyTransport struct {
	APIKey string

	// Transport to use when making requests, defaults to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

APIKeyTransport is a http.RoundTripper that adds the APIKey to each request.

func (*APIKeyTransport) Client

func (t *APIKeyTransport) Client() *http.Client

Client returns a *http.Client that makes APIKey authenticated requests

func (*APIKeyTransport) RoundTrip

func (t *APIKeyTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type Client

type Client struct {

	// Base URL for API requests. Defaults to the public DNSDB API. BaseURL should always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the DNSDB API.
	UserAgent string

	// Service are used for communication with the different parts of the DNSDB API.
	RRSet *RRSetService
	RData *RDataService
	// contains filtered or unexported fields
}

A Client manages communication with the DNSDB API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new DNSDB API client. It will fallback to http.DefaultClient if no client is provided

func (*Client) Do

func (c *Client) Do(req *http.Request) (*Response, error)

Do sends the provided http.Request and returns the response from DNSDB.

func (*Client) NewLookupRequest

func (c *Client) NewLookupRequest(method, urlStr string, opt LookupOptions) (*http.Request, error)

NewLookupRequest is a convienience function that extends NewRequest for Lookup methods

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an http.Request object or returns and error. A relative URL can be provided in urlStr

type LookupOptions

type LookupOptions struct {
	Limit           int64     `url:"limit,omitempty"`
	TimeFirstBefore time.Time `url:"time_first_before,omitempty"`
	TimeFirstAfter  time.Time `url:"time_first_after,omitempty"`
	TimeLastBefore  time.Time `url:"time_last_before,omitempty"`
	TimeLastAfter   time.Time `url:"time_last_after,omitempty"`
}

LookupOptions defines the optional parameters to all lookup calls

type RData

type RData struct {
	Count         *uint64    `json:"count"`
	TimeFirst     *Timestamp `json:"time_first"`
	TimeLast      *Timestamp `json:"time_last"`
	ZoneTimeFirst *Timestamp `json:"zone_time_first"`
	ZoneTimeLast  *Timestamp `json:"zone_time_last"`
	RRName        *string    `json:"rrname"`
	RRType        *string    `json:"rrtype"`
	RData         *string    `json:"rdata"`
}

RData as described at https://api.dnsdb.info/#rdata-lookups

type RDataLookupIPNetOptions

type RDataLookupIPNetOptions struct {
	RRType string

	LookupOptions
}

RDataLookupIPNetOptions specifies the optional parameters to the RDataService.LookupIPNet method.

type RDataLookupIPOptions

type RDataLookupIPOptions struct {
	RRType string

	LookupOptions
}

RDataLookupIPOptions specifies the optional parameters to the RDataService.LookupIP method.

type RDataLookupNameOptions

type RDataLookupNameOptions struct {
	RRType string

	LookupOptions
}

RDataLookupNameOptions specifies the optional parameters to the RDataService.LookupName method.

type RDataLookupRawOptions

type RDataLookupRawOptions struct {
	RRType string

	LookupOptions
}

RDataLookupRawOptions specifies the optional parameters to the RDataService.LookupRaw method.

type RDataService

type RDataService service

RDataService communicates with the rdata related methods of the DNSDB API.

func (*RDataService) LookupIP

func (s *RDataService) LookupIP(ip net.IP, opt *RDataLookupIPOptions) ([]RData, *Response, error)

LookupIP fetches all matching records for the provided IP

func (*RDataService) LookupIPNet

func (s *RDataService) LookupIPNet(ipnet net.IPNet, opt *RDataLookupIPNetOptions) ([]RData, *Response, error)

LookupIPNet fetches all matching records for the provided IPNet

func (*RDataService) LookupName

func (s *RDataService) LookupName(name string, opt *RDataLookupNameOptions) ([]RData, *Response, error)

LookupName fetches all matching records for the provided name

func (*RDataService) LookupRaw

func (s *RDataService) LookupRaw(raw []byte, opt *RDataLookupRawOptions) ([]RData, *Response, error)

LookupRaw fetches all matching records for the provided raw bytes and optional RRType (set to "")

type RRSet

type RRSet struct {
	Count         *uint64    `json:"count"`
	Bailiwick     *string    `json:"bailiwick"`
	TimeFirst     *Timestamp `json:"time_first"`
	TimeLast      *Timestamp `json:"time_last"`
	ZoneTimeFirst *Timestamp `json:"zone_time_first"`
	ZoneTimeLast  *Timestamp `json:"zone_time_last"`
	RRName        *string    `json:"rrname"`
	RRType        *string    `json:"rrtype"`
	RData         []string   `json:"rdata"`
}

RRSet as described at https://api.dnsdb.info/#rrest-results

type RRSetLookupNameOptions

type RRSetLookupNameOptions struct {
	RRType    string
	Bailiwick string

	LookupOptions
}

RRSetLookupNameOptions specifies the optional parameters to the RRSetService.LookupName method.

type RRSetService

type RRSetService service

RRSetService communicates with the rrset related methods of the DNSDB API.

func (*RRSetService) LookupName

func (s *RRSetService) LookupName(ownerName string, opt *RRSetLookupNameOptions) ([]RRSet, *Response, error)

LookupName fetches all matching records for the given owner name

type Rate

type Rate struct {
	Limit     int       `json: "reset"`
	Remaining int       `json: "limit"`
	Reset     Timestamp `json: "remaining"`
}

Rate represents the current rate limit

type Response

type Response struct {
	*http.Response

	Rate
}

Response is a DNSDB API response. We wrap the standard http.Response and provided the Rate object from the response

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time generated from a JSON string

func NewTimestamp

func NewTimestamp(secs int64) *Timestamp

Make a new Timestamp from a unix timestamp

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON helps unmarshal UNIX dates in JSON

Jump to

Keyboard shortcuts

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