Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Jun 30, 2023
1 parent f7a6981 commit 568ded9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
39 changes: 36 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ func init() {
d := net.Dialer{
Timeout: time.Second * 5,
}
dnsServers := []string{"1.0.0.1", "8.8.4.4", "223.5.5.5", "223.6.6.6"}
dnsServers := []string{
"1.0.0.1:53", "8.8.4.4:53", "223.5.5.5:53", "223.6.6.6:53",
"[2606:4700:4700::1001]:53", "[2001:4860:4860::8844]:53", "[2400:3200::1]:53", "[2400:3200:baba::1]:53",
}
if len(agentConfig.DNS) > 0 {
dnsServers = agentConfig.DNS
}
dnsServer := dnsServers[time.Now().Unix()%int64(len(dnsServers))]
return d.DialContext(ctx, "udp", dnsServer+":53")
return d.DialContext(ctx, "udp", dnsServer)
}
flag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true

Expand Down Expand Up @@ -130,7 +136,7 @@ func main() {
// 初始化运行参数
var isEditAgentConfig bool
flag.BoolVarP(&agentCliParam.Debug, "debug", "d", false, "开启调试信息")
flag.BoolVarP(&isEditAgentConfig, "edit-agent-config", "", false, "修改要监控的网卡/分区白名单")
flag.BoolVarP(&isEditAgentConfig, "edit-agent-config", "c", false, "修改要监控的网卡/分区名单,修改自定义 DNS")
flag.StringVarP(&agentCliParam.Server, "server", "s", "localhost:5555", "管理面板RPC端口")
flag.StringVarP(&agentCliParam.ClientSecret, "password", "p", "", "Agent连接Secret")
flag.IntVar(&agentCliParam.ReportDelay, "report-delay", 1, "系统状态上报间隔")
Expand Down Expand Up @@ -567,11 +573,19 @@ func editAgentConfig() {
Options: diskAllowlistOptions,
},
},
{
Name: "dns",
Prompt: &survey.Input{
Message: "自定义 DNS,可输入空格跳过,如 1.1.1.1:53,1.0.0.1:53",
Default: strings.Join(agentConfig.DNS, ","),
},
},
}

answers := struct {
Nic []string
Disk []string
DNS string
}{}

err = survey.Ask(qs, &answers, survey.WithValidator(survey.Required))
Expand All @@ -590,6 +604,25 @@ func editAgentConfig() {
agentConfig.NICAllowlist[v] = true
}

dnsServers := strings.TrimSpace(answers.DNS)

if dnsServers != "" {
agentConfig.DNS = strings.Split(dnsServers, ",")
for _, s := range agentConfig.DNS {
host, _, err := net.SplitHostPort(s)
if err == nil {
if net.ParseIP(host) == nil {
err = errors.New("格式错误")
}
}
if err != nil {
panic(fmt.Sprintf("自定义 DNS 格式错误:%s %v", s, err))
}
}
} else {
agentConfig.DNS = []string{}
}

if err = agentConfig.Save(); err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type AgentConfig struct {
HardDrivePartitionAllowlist []string
NICAllowlist map[string]bool
DNS []string
v *viper.Viper
}

Expand Down

1 comment on commit 568ded9

@Erope
Copy link
Member

@Erope Erope commented on 568ded9 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dnsServers中,v4和v6的混一起了,但每次Lookup都只会查随机的一个dns,如果v4随到了v6的dns,或v6随到了v4的dns就寄了

Please sign in to comment.