blob: c1b7a08adbbc03fc4819163096c95e22db066720 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
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"
}
|