util

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2015 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

This contains some usefull functions.

Dial function will try to connect to the ipv6 address one by one, if all failed, it fallback to connect to ipv4 address one by one.

ResolveA returns all ipv4 address for the domain.

ResolveAAAA returns all the ipv6 address for the domain.

ResolveDns return all the ipv6 and ipv4 address, and ipv6 first.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	/* dial timeout */
	DialTimeout time.Duration = 0

	/* default timeout, 300ms */
	DefaultDialTimeout time.Duration = 300 * time.Millisecond
)
View Source
var (
	/* dns server to use */
	DnsServer string

	/* default dns server */
	DefaultDnsServer = "8.8.8.8:53"
)

Functions

func Dial

func Dial(network string, addr string) (net.Conn, error)

Try to dial all the ip address one by one if addr is a domain name, util one is successed.

It tries to dail to ipv6 first, and then dial to ipv4 until one is successed

If dial to all ip failed, it return a error.

func ResolveA

func ResolveA(d string) ([]net.IP, error)

Return all the ipv4 address for the domain name.

If domain name resolve failed or get an emppty ip list will return an error.

Instead of system dns utils, we use the pure go dns library from https://github.com/miekg/dns

Example
res, err := ResolveA("mail.google.com")
if err != nil {
	log.Fatal(err)
}
for _, ip := range res {
	fmt.Printf("%s\n", ip.String())
}
Output:

74.125.203.17
74.125.203.19
74.125.203.18
74.125.203.83

func ResolveAAAA

func ResolveAAAA(d string) ([]net.IP, error)

Return all the ipv6 address for the domain name.

If domain name resolve failed or get an emppty ip list will return an error.

Instead of system dns utils, we use the pure go dns library from https://github.com/miekg/dns

Example
res, err := ResolveAAAA("mail.google.com")
if err != nil {
	log.Fatal(err)
}
for _, ip := range res {
	fmt.Printf("%s\n", ip.String())
}
Output:

2404:6800:4005:80a::2005

func ResolveDns

func ResolveDns(d string) ([]net.IP, error)

Return all the ipv6 and ipv4 address for the domain name.

In the return list, ipv6 address is in front of ipv4 address.

if domain name resolve failed it will return an error.

Instead of system dns utils, we use the pure go dns library from https://github.com/miekg/dns

Example
res, err := ResolveDns("mail.google.com")
if err != nil {
	log.Fatal(err)
}
for _, ip := range res {
	fmt.Printf("%s\n", ip.String())
}
Output:

2404:6800:4005:80a::2005
74.125.203.17
74.125.203.19
74.125.203.18
74.125.203.83

Types

This section is empty.

Jump to

Keyboard shortcuts

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