neo-go/pkg/wire/util/ip/ip.go

21 lines
338 B
Go
Raw Normal View History

2019-02-25 22:44:14 +00:00
package iputils
import (
"log"
"net"
)
//GetLocalIP returns the ip address of the current node
2019-02-25 22:44:14 +00:00
// 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
}