1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00

add IPv6 support for DuckDNS

This commit is contained in:
Timothy 2020-02-06 22:33:55 +08:00
parent 456e01df61
commit 162b639019
No known key found for this signature in database
GPG Key ID: DA25A2861AA0F2D1

View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"runtime/debug"
"strings"
"time"
"github.com/TimothyYe/godns"
@ -12,7 +13,7 @@ import (
var (
// DuckUrl the API address for Duck DNS
DuckUrl = "https://www.duckdns.org/update?domains=%s&token=%s&ip=%s"
DuckUrl = "https://www.duckdns.org/update?domains=%s&token=%s&%s"
)
// Handler struct
@ -51,10 +52,17 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
} else {
lastIP = currentIP
client := godns.GetHttpClient(handler.Configuration)
var ip string
if strings.ToUpper(handler.Configuration.IPType) == godns.IPV4 {
ip = fmt.Sprintf("ip=%s", currentIP)
} else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 {
ip = fmt.Sprintf("ipv6=%s", currentIP)
}
for _, subDomain := range domain.SubDomains {
// update IP with HTTP GET request
resp, err := client.Get(fmt.Sprintf(DuckUrl, subDomain, handler.Configuration.LoginToken, currentIP))
resp, err := client.Get(fmt.Sprintf(DuckUrl, subDomain, handler.Configuration.LoginToken, ip))
if err != nil {
// handle error
log.Print("Failed to update sub domain:", subDomain)
@ -65,8 +73,7 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
body, err := ioutil.ReadAll(resp.Body)
if err != nil || string(body) != "OK" {
// handle error
log.Print("Failed to update sub domain:", subDomain, err.Error())
log.Println("Failed to update the IP")
continue
} else {
log.Print("IP updated to:", currentIP)