mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
get ip, no proxy #63.
This commit is contained in:
parent
7e2baf432f
commit
93cb227a1f
@ -3,13 +3,29 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// dig @resolver1.opendns.com ANY myip.opendns.com +short -4
|
// dig @resolver1.opendns.com ANY myip.opendns.com +short -4
|
||||||
|
|
||||||
func GetIP() (string, error) {
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user