feat: Handle nameserver parsing on Windows
* system default nameserver in windows * change
This commit is contained in:
parent
250591098b
commit
3019f1cee6
5 changed files with 166 additions and 18 deletions
30
pkg/config/config_unix.go
Normal file
30
pkg/config/config_unix.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
// +build !windows
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
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