From 93cb227a1f9f6db725274c1ac20f4ab60e6d9bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 29 May 2021 21:08:41 +0200 Subject: [PATCH] get ip, no proxy #63. --- server/internal/utils/ip.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 }