gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/net/ip_address.go (about) 1 package net 2 3 import "net" 4 5 // GetLocalIPAddressString returns the local IP address used by Ignition Store IP() method. 6 func GetLocalIPAddressString() (string, error) { 7 addrs, err := net.InterfaceAddrs() 8 if err != nil { 9 return "", err 10 } 11 var ip string 12 for _, address := range addrs { 13 // check the address type and if it is not a loopback the display it 14 if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { 15 if ipnet.IP.To4() != nil { 16 ip = ipnet.IP.String() 17 break 18 } 19 } 20 } 21 return ip, nil 22 }