Skip to content

Commit

Permalink
feat: Ensure that the correctly obtained IP can be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yzy613 committed Jun 9, 2024
1 parent 5b4eead commit 3030aef
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 3 additions & 1 deletion cmd/ddns-watchdog-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ func check() {
ipv4, ipv6, err := client.GetOwnIP(client.Client.Enable, client.Client.APIUrl, client.Client.NetworkCard)
if err != nil {
log.Println(err)
return
if ipv4 == "" && ipv6 == "" {
return
}
}

// 进入更新流程
Expand Down
4 changes: 2 additions & 2 deletions internal/client/alidns.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (ad *AliDNS) LoadConf() (err error) {
}

func (ad *AliDNS) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string, errs []error) {
if enabled.IPv4 && ad.SubDomain.A != "" {
if ipv4 != "" && enabled.IPv4 && ad.SubDomain.A != "" {
// 获取解析记录
recordId, recordIP, err := ad.getParseRecord(ad.SubDomain.A, "A")
if err != nil {
Expand All @@ -58,7 +58,7 @@ func (ad *AliDNS) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string, e
}
}
}
if enabled.IPv6 && ad.SubDomain.AAAA != "" {
if ipv6 != "" && enabled.IPv6 && ad.SubDomain.AAAA != "" {
// 获取解析记录
recordId, recordIP, err := ad.getParseRecord(ad.SubDomain.AAAA, "AAAA")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/client/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (cfc *Cloudflare) LoadConf() (err error) {
}

func (cfc *Cloudflare) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string, errs []error) {
if enabled.IPv4 && cfc.Domain.A != "" {
if ipv4 != "" && enabled.IPv4 && cfc.Domain.A != "" {
// 获取解析记录
domainId, recordIP, err := cfc.getParseRecord(cfc.Domain.A, "A")
if err != nil {
Expand All @@ -69,7 +69,7 @@ func (cfc *Cloudflare) Run(enabled common.Enable, ipv4, ipv6 string) (msg []stri
}
}
}
if enabled.IPv6 && cfc.Domain.AAAA != "" {
if ipv6 != "" && enabled.IPv6 && cfc.Domain.AAAA != "" {
// 获取解析记录
domainId, recordIP, err := cfc.getParseRecord(cfc.Domain.AAAA, "AAAA")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/client/dnspod.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (dpc *DNSPod) LoadConf() (err error) {
}

func (dpc *DNSPod) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string, errs []error) {
if enabled.IPv4 && dpc.SubDomain.A != "" {
if ipv4 != "" && enabled.IPv4 && dpc.SubDomain.A != "" {
// 获取解析记录
recordId, recordLineId, recordIP, err := dpc.getParseRecord(dpc.SubDomain.A, "A")
if err != nil {
Expand All @@ -61,7 +61,7 @@ func (dpc *DNSPod) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string,
}
}
}
if enabled.IPv6 && dpc.SubDomain.AAAA != "" {
if ipv6 != "" && enabled.IPv6 && dpc.SubDomain.AAAA != "" {
// 获取解析记录
recordId, recordLineId, recordIP, err := dpc.getParseRecord(dpc.SubDomain.AAAA, "AAAA")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/client/huaweicloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (hc *HuaweiCloud) Run(enabled common.Enable, ipv4, ipv6 string) (msg []stri
return
}
}
if enabled.IPv4 && hc.Domain.A != "" {
if ipv4 != "" && enabled.IPv4 && hc.Domain.A != "" {
recordSetId, recordIP, err := hc.getParseRecord(hc.Domain.A, "A")
if err != nil {
errs = append(errs, err)
Expand All @@ -67,7 +67,7 @@ func (hc *HuaweiCloud) Run(enabled common.Enable, ipv4, ipv6 string) (msg []stri
}
}
}
if enabled.IPv6 && hc.Domain.AAAA != "" {
if ipv6 != "" && enabled.IPv6 && hc.Domain.AAAA != "" {
recordSetId, recordIP, err := hc.getParseRecord(hc.Domain.AAAA, "AAAA")
if err != nil {
errs = append(errs, err)
Expand Down
6 changes: 2 additions & 4 deletions internal/client/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func GetOwnIP(enabled common.Enable, apiUrl apiUrl, nc networkCard) (ipv4, ipv6
ipv4 = v
} else {
err = errors.New("IPv4 选择了不存在的网卡")
return
}
} else {
// 使用 API 获取 IPv4
Expand Down Expand Up @@ -173,7 +172,7 @@ func GetOwnIP(enabled common.Enable, apiUrl apiUrl, nc networkCard) (ipv4, ipv6
}
if strings.Contains(ipv4, ":") {
err = errors.New("获取到的 IPv4 格式错误,意外获取到了 " + ipv4)
return
ipv4 = ""
}
}

Expand All @@ -185,7 +184,6 @@ func GetOwnIP(enabled common.Enable, apiUrl apiUrl, nc networkCard) (ipv4, ipv6
ipv6 = v
} else {
err = errors.New("IPv6 选择了不存在的网卡")
return
}
} else {
// 使用 API 获取 IPv4
Expand Down Expand Up @@ -219,7 +217,7 @@ func GetOwnIP(enabled common.Enable, apiUrl apiUrl, nc networkCard) (ipv4, ipv6
ipv6 = common.ExpandIPv6Zero(ipv6)
} else {
err = errors.New("获取到的 IPv6 格式错误,意外获取到了 " + ipv6)
return
ipv6 = ""
}
}
return
Expand Down
2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
LocalVersion = "1.5.8"
LocalVersion = "1.5.9"
DefaultAPIUrl = "https://yzyweb.cn/ddns-watchdog"
DefaultIPv6APIUrl = "https://yzyweb.cn/ddns-watchdog6"
ProjectUrl = "https://github.com/yzy613/ddns-watchdog"
Expand Down

0 comments on commit 3030aef

Please sign in to comment.