Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/utils/ip.go

25 lines
390 B
Go
Raw Normal View History

2020-02-10 20:13:40 +13:00
package utils
import (
"bytes"
"io/ioutil"
"net/http"
)
// dig @resolver1.opendns.com ANY myip.opendns.com +short -4
func GetIP() (string, error) {
rsp, err := http.Get("http://checkip.amazonaws.com")
if err != nil {
return "", err
}
defer rsp.Body.Close()
buf, err := ioutil.ReadAll(rsp.Body)
if err != nil {
return "", err
}
return string(bytes.TrimSpace(buf)), nil
}