增加防火墙规则:
func addFireWall(names, appnames,dirs,actions string) error {
c := exec.Command("netsh", "advfirewall", "firewall", "add", "rule",
"name="+names,
"dir="+dirs,
"action="+actions,
"program="+appnames,
)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
}
还可以这样:
cmdArgs := []string{"advfirewall", "firewall",
"add","rule","name=MyService","dir=in",
"action=allow","program=x:\\xxxxx\\xxxx\\xxxxx.exe"}
out,err:=exec.Command("netsh",cmdArgs...).Output()
if err !=nil{
fmt.Println("err:::",err)
}
fmt.Println("Out::",string(out))
删除防火墙规则:
func delFireWall(name string) error {
cmd := exec.Command("netsh", "ad