f8979fe7af
* golint and minor changes to make code readable
20 lines
338 B
Go
20 lines
338 B
Go
package iputils
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
)
|
|
|
|
//GetLocalIP returns the ip address of the current node
|
|
// https://stackoverflow.com/a/37382208
|
|
func GetLocalIP() net.IP {
|
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
|
|
|
return localAddr.IP
|
|
}
|