From dd05670e1f55b5dffb70297345df43e186f8a075 Mon Sep 17 00:00:00 2001 From: Nelson Murilo Date: Thu, 13 Mar 2025 14:03:10 -0400 Subject: [PATCH] Update net_linux.go Code Review --- network/net_linux.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/network/net_linux.go b/network/net_linux.go index f73f6b3f..04fcd123 100644 --- a/network/net_linux.go +++ b/network/net_linux.go @@ -41,7 +41,9 @@ func SetInterfaceChannel(iface string, channel int) error { if core.HasBinary("iw") { // Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel) - out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)}) + // out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)}) + out, err := core.Exec("iw", []string{"dev", iface, "set", "freq", fmt.Sprintf("%d", Dot11Chan2Freq(channel))}) + if err != nil { return fmt.Errorf("iw: out=%s err=%s", out, err) } else if out != "" { @@ -89,7 +91,8 @@ func iwlistSupportedFrequencies(iface string) ([]int, error) { } var iwPhyParser = regexp.MustCompile(`^\s*wiphy\s+(\d+)$`) -var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\s+MHz.+dBm.+$`) +// var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\s+MHz.+dBm.+$`) +var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\.\d+\s+MHz.+dBm.+$`) func iwSupportedFrequencies(iface string) ([]int, error) { // first determine phy index @@ -140,10 +143,11 @@ func iwSupportedFrequencies(iface string) ([]int, error) { func GetSupportedFrequencies(iface string) ([]int, error) { // give priority to iwlist because of https://github.com/bettercap/bettercap/issues/881 - if core.HasBinary("iwlist") { - return iwlistSupportedFrequencies(iface) - } else if core.HasBinary("iw") { + // UPDATE: Changed the priority due iwlist doesn't support 6GHz + if core.HasBinary("iw") { return iwSupportedFrequencies(iface) + } else if core.HasBinary("iwlist") { + return iwlistSupportedFrequencies(iface) } return nil, fmt.Errorf("no iw or iwlist binaries found in $PATH")