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
427 B

  1. package util
  2. import (
  3. "net"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. )
  6. func DetectedHostAddress() string {
  7. addrs, err := net.InterfaceAddrs()
  8. if err != nil {
  9. glog.V(0).Infof("failed to detect ip address: %v", err)
  10. return ""
  11. }
  12. for _, a := range addrs {
  13. if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
  14. if ipnet.IP.To4() != nil {
  15. return ipnet.IP.String()
  16. }
  17. }
  18. }
  19. return "localhost"
  20. }