change
This commit is contained in:
parent
d873dc5b35
commit
4fda3714f1
3 changed files with 32 additions and 15 deletions
|
@ -3,17 +3,28 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
//DefaultResolvConfPath specifies path to default resolv config file on UNIX.
|
||||
// DefaultResolvConfPath specifies path to default resolv config file on UNIX.
|
||||
const DefaultResolvConfPath = "/etc/resolv.conf"
|
||||
|
||||
// GetDefaultServers get system default nameserver
|
||||
func GetDefaultServers() ([]string, int, []string, error) {
|
||||
// if no nameserver is provided, take it from `resolv.conf`
|
||||
cfg, err := dns.ClientConfigFromFile(DefaultResolvConfPath)
|
||||
if err != nil {
|
||||
return nil, 0, nil, err
|
||||
}
|
||||
return cfg.Servers, cfg.Ndots, cfg.Search, nil
|
||||
servers := make([]string, 0)
|
||||
for _, server := range cfg.Servers {
|
||||
ip := net.ParseIP(server)
|
||||
if isUnicastLinkLocal(ip) {
|
||||
continue
|
||||
}
|
||||
servers = append(servers, server)
|
||||
}
|
||||
return servers, cfg.Ndots, cfg.Search, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue