"io/ioutil"
"os"
"os/exec"
+ "regexp"
"sort"
"strings"
"syscall"
}
// remove scope ID if present
f = bytes.Split(f[1], []byte{'%'})
+
+ // netsh can create IPv4-embedded IPv6 addresses, like fe80::5efe:192.168.140.1.
+ // Convert these to all hexadecimal fe80::5efe:c0a8:8c01 for later string comparisons.
+ ipv4Tail := regexp.MustCompile(`:\d+\.\d+\.\d+\.\d+$`)
+ if ipv4Tail.Match(f[0]) {
+ f[0] = []byte(ParseIP(string(f[0])).String())
+ }
+
addrs = append(addrs, string(bytes.ToLower(bytes.TrimSpace(f[0]))))
}
return addrs, nil
}
func TestInterfaceAddrsWithNetsh(t *testing.T) {
- t.Skip("see https://golang.org/issue/13981")
-
if isWindowsXP(t) {
t.Skip("Windows XP netsh command does not provide required functionality")
}
t.Fatal(err)
}
for _, ifi := range ift {
+ // Skip the interface if it's down.
+ if (ifi.Flags & FlagUp) == 0 {
+ continue
+ }
have := make([]string, 0)
addrs, err := ifi.Addrs()
if err != nil {