MCPcopy
hub / github.com/EverythingSuckz/TG-FileStreamBot / getInternalIP

Function getInternalIP

config/config.go:254–262  ·  view source on GitHub ↗

https://stackoverflow.com/a/23558495/15807350

()

Source from the content-addressed store, hash-verified

252
253// https://stackoverflow.com/a/23558495/15807350
254func 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
264func GetPublicIP() (string, error) {
265 resp, err := http.Get("https://api.ipify.org?format=text")

Callers 1

getIPFunction · 0.85

Calls 2

CloseMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected