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

Integrate with socks5 proxy

This commit is contained in:
Timothy 2017-10-09 20:23:24 +08:00
parent 7e9bd7f532
commit 9b458a0d1d
3 changed files with 45 additions and 13 deletions

View File

@ -12,7 +12,7 @@ const (
PANIC_MAX = 5
// INTERVAL is minute
INTERVAL = 5
// DNSPod
// DNSPOD
DNSPOD = "DNSPod"
// HE
HE = "HE"

View File

@ -7,8 +7,8 @@ import (
"os"
"runtime/debug"
"time"
"github.com/parnurzeal/gorequest"
"io/ioutil"
"golang.org/x/net/proxy"
)
var (
@ -53,20 +53,34 @@ func (handler *HEHandler) DomainLoop(domain *Domain) {
}
func (handler *HEHandler) UpdateIP(domain, subDomain, currentIP string) {
request := gorequest.New()
resp, body, errs := request.Get(fmt.Sprintf(HEUrl, subDomain, domain, configuration.Password, currentIP)).End()
client := &http.Client{}
if len(errs) > 0 {
log.Println("Request error...")
for _, err := range errs {
log.Println("Err:", err.Error())
if configuration.Socks5Proxy != "" {
log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
if err != nil {
log.Println("can't connect to the proxy:", err)
return
}
httpTransport := &http.Transport{}
client.Transport = httpTransport
httpTransport.Dial = dialer.Dial
}
resp, err := client.Get(fmt.Sprintf(HEUrl, subDomain, domain, configuration.Password, currentIP))
if err != nil {
log.Println("Request error...")
log.Println("Err:", err.Error())
} else {
body, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode == http.StatusOK {
log.Println("Update IP success:", body)
log.Println("Update IP success:", string(body))
} else {
log.Println("Update IP failed:", body)
log.Println("Update IP failed:", string(body))
}
}
}

View File

@ -9,10 +9,28 @@ import (
"net/http"
"runtime"
"strings"
"golang.org/x/net/proxy"
)
func getCurrentIP(url string) (string, error) {
response, err := http.Get(url)
client := &http.Client{}
if configuration.Socks5Proxy != "" {
log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
if err != nil {
fmt.Println("can't connect to the proxy:", err)
return "", err
}
httpTransport := &http.Transport{}
client.Transport = httpTransport
httpTransport.Dial = dialer.Dial
}
response, err := client.Get(url)
if err != nil {
log.Println("Cannot get IP...")