1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-05 07:50:24 +08:00
Files
WireGold/lower/tun_windows.go
2024-08-03 16:42:16 +08:00

30 lines
842 B
Go

//go:build windows
// +build windows
package lower
import "net"
func (n *NICIO) Up() {
execute("cmd", "/c", "netsh interface ip set address name=\""+n.ifce.Name()+"\" source=static addr=\""+n.ip.String()+"\" mask=\""+(net.IP)(n.subnet.Mask).String()+"\" gateway=none")
execute("cmd", "/c", "netsh interface ipv4 set subinterface \""+n.ifce.Name()+"\" mtu="+n.mtu)
for _, c := range n.cidrs {
ip, cidr, err := net.ParseCIDR(c)
if err != nil {
panic(err)
}
execute("cmd", "/c", "route ADD "+ip.String()+" MASK "+(net.IP)(cidr.Mask).String()+" "+n.ip.String())
}
}
func (n *NICIO) Down() {
// execute("netsh", "interface", "set", "interface", n.ifce.Name(), "disabled")
for _, c := range n.cidrs {
ip, _, err := net.ParseCIDR(c)
if err != nil {
panic(err)
}
execute("cmd", "/c", "route DELETE "+ip.String())
}
}