https://stackoverflow.com/a/23558495/15807350
()
| 252 | |
| 253 | // https://stackoverflow.com/a/23558495/15807350 |
| 254 | func getInternalIP() (string, error) { |
| 255 | conn, err := net.Dial("udp", "8.8.8.8:80") |
| 256 | if err != nil { |
| 257 | return "", errors.New("no internet connection") |
| 258 | } |
| 259 | defer conn.Close() |
| 260 | localAddr := conn.LocalAddr().(*net.UDPAddr) |
| 261 | return localAddr.IP.String(), nil |
| 262 | } |
| 263 | |
| 264 | func GetPublicIP() (string, error) { |
| 265 | resp, err := http.Get("https://api.ipify.org?format=text") |