supply default dns server

This commit is contained in:
lsy1990 2022-07-26 10:45:26 +08:00
parent 8f60ccafd0
commit cfba6f692e
2 changed files with 21 additions and 1 deletions

View File

@ -8,6 +8,9 @@
# # interval = global.interval * interval_times
# interval_times = 1
# #
enable = false
## servers to query
# servers = ["8.8.8.8"]
servers = []

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net"
"os"
"strconv"
"sync"
"time"
@ -48,6 +49,7 @@ func (dq *DnsQuery) GetInstances() []inputs.Instance {
type Instance struct {
config.InstanceConfig
Enable bool `toml:"enable"`
// Domains or subdomains to query
Domains []string `toml:"domains"`
@ -68,8 +70,23 @@ type Instance struct {
}
func (ins *Instance) Init() error {
if ins.Enable == false {
return nil
}
if len(ins.Servers) == 0 {
return types.ErrInstancesEmpty
resolvPath := "/etc/resolv.conf"
if _, err := os.Stat(resolvPath); os.IsNotExist(err) {
return nil
}
config, _ := dns.ClientConfigFromFile(resolvPath)
Servers := []string{}
for _, ipAddress := range config.Servers {
Servers = append(Servers, ipAddress)
}
ins.Servers = Servers
if len(ins.Servers) == 0 {
return nil
}
}
if ins.Network == "" {