mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
28 lines
552 B
Go
28 lines
552 B
Go
|
//go:build !windows
|
||
|
|
||
|
package dns
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"regexp"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
// nameserver xxx.xxx.xxx.xxx
|
||
|
nameserverPattern = regexp.MustCompile(`nameserver\s+(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})`)
|
||
|
)
|
||
|
|
||
|
func dnsReadConfig() (servers []string, err error) {
|
||
|
content, err := os.ReadFile("/etc/resolv.conf")
|
||
|
if err != nil {
|
||
|
err = fmt.Errorf("failed to read /etc/resolv.conf: %w", err)
|
||
|
return
|
||
|
}
|
||
|
for _, line := range nameserverPattern.FindAllStringSubmatch(string(content), -1) {
|
||
|
addr := line[1]
|
||
|
servers = append(servers, addr)
|
||
|
}
|
||
|
return
|
||
|
}
|