system default nameserver in windows

This commit is contained in:
huangnauh 2021-01-19 19:35:53 +08:00
parent 250591098b
commit d873dc5b35
4 changed files with 149 additions and 18 deletions

19
pkg/config/config_unix.go Normal file
View file

@ -0,0 +1,19 @@
// +build !windows
package config
import (
"github.com/miekg/dns"
)
//DefaultResolvConfPath specifies path to default resolv config file on UNIX.
const DefaultResolvConfPath = "/etc/resolv.conf"
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
}