mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
rename nic in case of name have space
This commit is contained in:
20
pkg/main.go
20
pkg/main.go
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user