mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
refactor update IP logic
This commit is contained in:
parent
564ceee22d
commit
ceb8ee8548
@ -2,17 +2,20 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"io/ioutil"
|
|
||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
HEUrl = "https://dyn.dns.he.net/nic/update?hostname=%s.%s&password=%s&myip=%s"
|
HEUrl = "https://dyn.dns.he.net/nic/update"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HEHandler struct{}
|
type HEHandler struct{}
|
||||||
@ -53,24 +56,28 @@ func (handler *HEHandler) DomainLoop(domain *Domain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *HEHandler) UpdateIP(domain, subDomain, currentIP string) {
|
func (handler *HEHandler) UpdateIP(domain, subDomain, currentIP string) {
|
||||||
|
values := url.Values{}
|
||||||
|
values.Add("hostname", fmt.Sprintf("%s.%s", subDomain, domain))
|
||||||
|
values.Add("password", configuration.Password)
|
||||||
|
values.Add("myip", currentIP)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
if configuration.Socks5Proxy != "" {
|
if configuration.Socks5Proxy != "" {
|
||||||
|
|
||||||
log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
|
log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
|
||||||
|
|
||||||
dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
|
dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("can't connect to the proxy:", err)
|
log.Println("can't connect to the proxy:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
httpTransport := &http.Transport{}
|
httpTransport := &http.Transport{}
|
||||||
client.Transport = httpTransport
|
client.Transport = httpTransport
|
||||||
httpTransport.Dial = dialer.Dial
|
httpTransport.Dial = dialer.Dial
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Get(fmt.Sprintf(HEUrl, subDomain, domain, configuration.Password, currentIP))
|
req, _ := http.NewRequest("POST", HEUrl, strings.NewReader(values.Encode()))
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Request error...")
|
log.Println("Request error...")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user