You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
425 B
25 lines
425 B
package util
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util/log"
|
|
)
|
|
|
|
func DetectedHostAddress() string {
|
|
addrs, err := net.InterfaceAddrs()
|
|
if err != nil {
|
|
log.Infof("failed to detect ip address: %v", err)
|
|
return ""
|
|
}
|
|
|
|
for _, a := range addrs {
|
|
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
|
if ipnet.IP.To4() != nil {
|
|
return ipnet.IP.String()
|
|
}
|
|
}
|
|
}
|
|
|
|
return "localhost"
|
|
}
|