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 ¶
var ( /* dial timeout */ DialTimeout time.Duration = 0 /* default timeout, 300ms */ DefaultDialTimeout time.Duration = 300 * time.Millisecond )
var ( /* dns server to use */ DnsServer string /* default dns server */ DefaultDnsServer = "8.8.8.8:53" )
Functions ¶
func Dial ¶
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 ¶
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 ¶
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 ¶
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.