mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
fix: using netsh exit status instead of output message in order to avoid issues with localization (fixes #186)
This commit is contained in:
parent
eb0ca12ec6
commit
02da4a0cbd
1 changed files with 4 additions and 25 deletions
|
@ -35,26 +35,14 @@ func (f WindowsFirewall) IsForwardingEnabled() bool {
|
|||
}
|
||||
}
|
||||
|
||||
func (f WindowsFirewall) isSuccess(output string) bool {
|
||||
if trimmed := core.Trim(strings.ToUpper(output)); trimmed == "" || strings.Contains(trimmed, "OK") == true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (f WindowsFirewall) EnableForwarding(enabled bool) error {
|
||||
v := "enabled"
|
||||
if enabled == false {
|
||||
v = "disabled"
|
||||
}
|
||||
out, err := core.Exec("netsh", []string{"interface", "ipv4", "set", "interface", fmt.Sprintf("%d", f.iface.Index), fmt.Sprintf("forwarding=\"%s\"", v)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.isSuccess(out) == false {
|
||||
return fmt.Errorf("Unexpected netsh output: %s", out)
|
||||
if _, err := core.Exec("netsh", []string{"interface", "ipv4", "set", "interface", fmt.Sprintf("%d", f.iface.Index), fmt.Sprintf("forwarding=\"%s\"", v)}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -90,15 +78,10 @@ func (f *WindowsFirewall) AllowPort(port int, address string, proto string, allo
|
|||
cmd = []string{"advfirewall", "firewall", "delete", "rule", nameField, protoField, portField}
|
||||
}
|
||||
|
||||
out, err := core.Exec("netsh", cmd)
|
||||
if err != nil {
|
||||
if _, err := core.Exec("netsh", cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.isSuccess(out) == false {
|
||||
return fmt.Errorf("Unexpected netsh output: %s", out)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -116,14 +99,10 @@ func (f *WindowsFirewall) EnableRedirection(r *Redirection, enabled bool) error
|
|||
rule = append([]string{"interface", "portproxy", "delete", "v4tov4"}, rule...)
|
||||
}
|
||||
|
||||
out, err := core.Exec("netsh", rule)
|
||||
if err != nil {
|
||||
if _, err := core.Exec("netsh", rule); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.isSuccess(out) == false {
|
||||
return fmt.Errorf("Unexpected netsh output: %s", out)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue