20 lines
303 B
Go
20 lines
303 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
//获取本机ip
|
||
|
|
||
|
func GetBoundIP() (ip string, err error) {
|
||
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer conn.Close()
|
||
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||
|
ip = strings.Split(localAddr.String(), ":")[0]
|
||
|
return
|
||
|
}
|