dns_resolver

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2017 License: MIT Imports: 7 Imported by: 0

README

Simple dns resolver implemented in go

Build Status Go Walker

Based on based on miekg/dns.

Features

  • Uses provided dns servers array in random order
  • Retries dns requests in case of i/o timeout

Installing

Using go get
$ go get github.com/bogdanovich/dns_resolver

After this command dns_resolver is ready to use. Its source will be in:

$GOPATH/src/github.com/bogdanovich/dns_resolver

Example

package main

import (
	"log"
	"github.com/bogdanovich/dns_resolver"
)

func main() {
	resolver := dns_resolver.New([]string{"8.8.8.8", "8.8.4.4"})
	// OR
	// resolver := dns_resolver.NewFromResolvConf("resolv.conf")

	// In case of i/o timeout
	resolver.RetryTimes = 5

	ip, err := resolver.LookupHost("google.com")
	if err != nil {
		log.Fatal(err.Error())
	}
	log.Println(ip)
	// Output [216.58.192.46]
}

Documentation

Overview

Package dns_resolver is a simple dns resolver based on miekg/dns

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DnsResolver

type DnsResolver struct {
	Servers    []string
	RetryTimes int
	// contains filtered or unexported fields
}

DnsResolver represents a dns resolver

func New

func New(servers []string) *DnsResolver

New initializes DnsResolver.

func NewFromResolvConf

func NewFromResolvConf(path string) (*DnsResolver, error)

NewFromResolvConf initializes DnsResolver from resolv.conf like file.

func (*DnsResolver) LookupHost

func (r *DnsResolver) LookupHost(host string) ([]net.IP, error)

LookupHost returns IP addresses of provied host. In case of timeout retries query RetryTimes times.

Jump to

Keyboard shortcuts

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