22 lines
No EOL
335 B
Go
Executable file
22 lines
No EOL
335 B
Go
Executable file
package command
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
func GetPublicIp() (str string, err error) {
|
|
url := "https://api.ipify.org?format=text"
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
ip, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(ip), nil
|
|
} |