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

Merge pull request #8 from shellus/master

support socks5 proxy
This commit is contained in:
Timothy Ye 2017-07-19 21:54:52 +08:00 committed by GitHub
commit 3812d21c42
2 changed files with 19 additions and 2 deletions

View File

@ -9,7 +9,7 @@ import (
"net/url"
"strconv"
"strings"
"golang.org/x/net/proxy"
"github.com/bitly/go-simplejson"
)
@ -176,8 +176,24 @@ func updateIP(domainID int64, subDomainID string, subDomainName string, ip strin
func postData(url string, content url.Values) (string, error) {
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
}
values := generateHeader(content)
req, _ := http.NewRequest("POST", "https://dnsapi.cn"+url, strings.NewReader(values.Encode()))
req, _ := http.NewRequest("POST", "https://dnsapi.cn" + url, strings.NewReader(values.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", fmt.Sprintf("GoDNS/0.1 (%s)", configuration.Email))

View File

@ -22,6 +22,7 @@ type Settings struct {
LogPath string `json:"log_path"`
LogSize int `json:"log_size"`
LogNum int `json:"log_num"`
Socks5Proxy string `json:"socks5_proxy"`
}
//LoadSettings -- Load settings from config file