diff --git a/server/internal/utils/ip.go b/server/internal/utils/ip.go index 67c7d38d..fbdd1c66 100644 --- a/server/internal/utils/ip.go +++ b/server/internal/utils/ip.go @@ -3,13 +3,29 @@ package utils import ( "bytes" "io/ioutil" + "net" "net/http" + "time" ) // dig @resolver1.opendns.com ANY myip.opendns.com +short -4 func GetIP() (string, error) { - rsp, err := http.Get("http://checkip.amazonaws.com") + tr := &http.Transport{ + Proxy: nil, // ignore proxy + DialContext: (&net.Dialer{ + Timeout: 10 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + MaxIdleConns: 30, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 15 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + } + + client := &http.Client{Transport: tr} + rsp, err := client.Get("http://checkip.amazonaws.com") if err != nil { return "", err }