goutil/network.go

21 lines
323 B
Go

package goutil
import "net"
func GetIp() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return err.Error()
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return "none"
}