mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-27 12:35:39 +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
|
||
|
}
|