mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-13 05:45:02 +00:00
19 lines
282 B
Go
19 lines
282 B
Go
package iputils
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
)
|
|
|
|
// 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
|
|
}
|