rename nic in case of name have space

This commit is contained in:
wencaiwulue
2021-08-16 07:39:46 +08:00
parent 22f1715dda
commit 389ac30d09

View File

@@ -136,6 +136,7 @@ func prepare() {
if runtime.GOOS == "windows" {
exe.InstallTunTapDriver()
RenameNic()
}
}
@@ -254,3 +255,22 @@ func getCIDR(clientset *kubernetes.Clientset, ns string) (result []*net.IPNet, e
}
return nil, fmt.Errorf("can not found cidr")
}
func RenameNic() {
interfaces, _ := net.Interfaces()
for _, i := range interfaces {
if strings.Contains(i.Name, " ") {
out, err := exec.Command("netsh", []string{
"interface",
"set",
"interface",
fmt.Sprintf("name='%s'", i.Name),
"newname=" + strings.TrimSpace(i.Name),
}...).CombinedOutput()
if err != nil {
log.Warnf("rename %s --> %s failed, out: %s, error: %s",
i.Name, strings.TrimSpace(i.Name), string(out), err)
}
}
}
}