diff --git a/core/core.go b/core/core.go index b3b6436d..f79e6ffc 100644 --- a/core/core.go +++ b/core/core.go @@ -27,6 +27,13 @@ func UniqueInts(a []int, sorted bool) []int { return uniq } +func HasBinary(executable string) bool { + if path, err := exec.LookPath(executable); err != nil || path == "" { + return false + } + return true +} + func ExecSilent(executable string, args []string) (string, error) { path, err := exec.LookPath(executable) if err != nil { diff --git a/network/net.go b/network/net.go index 1c717bde..37123537 100644 --- a/network/net.go +++ b/network/net.go @@ -265,10 +265,12 @@ func FindInterface(name string) (*Endpoint, error) { } func SetWiFiRegion(region string) error { - if out, err := core.Exec("iw", []string{"reg", "set", region}); err != nil { - return err - } else if out != "" { - return fmt.Errorf("unexpected output while setting WiFi region %s: %s", region, out) + if core.HasBinary("iw") { + if out, err := core.Exec("iw", []string{"reg", "set", region}); err != nil { + return err + } else if out != "" { + return fmt.Errorf("unexpected output while setting WiFi region %s: %s", region, out) + } } return nil } @@ -283,10 +285,12 @@ func ActivateInterface(name string) error { } func SetInterfaceTxPower(name string, txpower int) error { - if out, err := core.ExecSilent("iwconfig", []string{name, "txpower", fmt.Sprintf("%d", txpower)}); err != nil { - return err - } else if out != "" { - return fmt.Errorf("unexpected output while setting txpower to %d for interface %s: %s", txpower, name, out) + if core.HasBinary("iwconfig") { + if out, err := core.ExecSilent("iwconfig", []string{name, "txpower", fmt.Sprintf("%d", txpower)}); err != nil { + return err + } else if out != "" { + return fmt.Errorf("unexpected output while setting txpower to %d for interface %s: %s", txpower, name, out) + } } return nil }