From 8b1e2ba0fa733000dff446d6fe17b2ad00fe1943 Mon Sep 17 00:00:00 2001 From: wuxingzhong <330332812@qq.com> Date: Thu, 8 Aug 2019 16:13:39 +0800 Subject: [PATCH] judge if interface is up --- pkg/net/ip/ip.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/net/ip/ip.go b/pkg/net/ip/ip.go index 54e241d1a..386d7e23f 100644 --- a/pkg/net/ip/ip.go +++ b/pkg/net/ip/ip.go @@ -48,6 +48,9 @@ func InternalIP() string { return "" } for _, inter := range inters { + if !isUp(inter.Flags) { + continue + } if !strings.HasPrefix(inter.Name, "lo") { addrs, err := inter.Addrs() if err != nil { @@ -64,3 +67,8 @@ func InternalIP() string { } return "" } + +// isUp Interface is up +func isUp(v net.Flags) bool { + return v&net.FlagUp == net.FlagUp +}