neo-go/_pkg.dev/wire/util/ip/ip.go
Roman Khimov ddd1d92ff1 pkg: hide it by moving to _pkg.dev
The idea here is to preserve the history of `dev` branch development and its
code when merging with the `master`. Later this code could be moved into the
masters code where appropriate.
2019-08-20 18:39:50 +03:00

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
}