22 lines
357 B
Go
22 lines
357 B
Go
|
package common
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
// https://stackoverflow.com/a/37382208
|
||
|
// Get preferred outbound ip of this machine
|
||
|
func GetOutboundIP() 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
|
||
|
}
|