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:
parent
456e01df61
commit
162b639019
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/TimothyYe/godns"
|
"github.com/TimothyYe/godns"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// DuckUrl the API address for Duck DNS
|
// 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
|
// Handler struct
|
||||||
@ -51,10 +52,17 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
} else {
|
} else {
|
||||||
lastIP = currentIP
|
lastIP = currentIP
|
||||||
client := godns.GetHttpClient(handler.Configuration)
|
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 {
|
for _, subDomain := range domain.SubDomains {
|
||||||
// update IP with HTTP GET request
|
// 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 {
|
if err != nil {
|
||||||
// handle error
|
// handle error
|
||||||
log.Print("Failed to update sub domain:", subDomain)
|
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)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil || string(body) != "OK" {
|
if err != nil || string(body) != "OK" {
|
||||||
// handle error
|
log.Println("Failed to update the IP")
|
||||||
log.Print("Failed to update sub domain:", subDomain, err.Error())
|
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
log.Print("IP updated to:", currentIP)
|
log.Print("IP updated to:", currentIP)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user