log-agent/utils/ip.go

20 lines
303 B
Go
Raw Permalink Normal View History

2024-09-10 20:46:31 +08:00
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
}