get ip, no proxy #63.

This commit is contained in:
Miroslav Šedivý 2021-05-29 21:08:41 +02:00
parent 7e2baf432f
commit 93cb227a1f

View File

@ -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
}