Update net_linux.go

Code Review
This commit is contained in:
Nelson Murilo 2025-03-13 14:03:10 -04:00 committed by GitHub
parent 4320b98e80
commit dd05670e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,7 +41,9 @@ func SetInterfaceChannel(iface string, channel int) error {
if core.HasBinary("iw") { if core.HasBinary("iw") {
// Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel) // 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 { if err != nil {
return fmt.Errorf("iw: out=%s err=%s", out, err) return fmt.Errorf("iw: out=%s err=%s", out, err)
} else if out != "" { } else if out != "" {
@ -89,7 +91,8 @@ func iwlistSupportedFrequencies(iface string) ([]int, error) {
} }
var iwPhyParser = regexp.MustCompile(`^\s*wiphy\s+(\d+)$`) 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) { func iwSupportedFrequencies(iface string) ([]int, error) {
// first determine phy index // first determine phy index
@ -140,10 +143,11 @@ func iwSupportedFrequencies(iface string) ([]int, error) {
func GetSupportedFrequencies(iface string) ([]int, error) { func GetSupportedFrequencies(iface string) ([]int, error) {
// give priority to iwlist because of https://github.com/bettercap/bettercap/issues/881 // give priority to iwlist because of https://github.com/bettercap/bettercap/issues/881
if core.HasBinary("iwlist") { // UPDATE: Changed the priority due iwlist doesn't support 6GHz
return iwlistSupportedFrequencies(iface) if core.HasBinary("iw") {
} else if core.HasBinary("iw") {
return iwSupportedFrequencies(iface) return iwSupportedFrequencies(iface)
} else if core.HasBinary("iwlist") {
return iwlistSupportedFrequencies(iface)
} }
return nil, fmt.Errorf("no iw or iwlist binaries found in $PATH") return nil, fmt.Errorf("no iw or iwlist binaries found in $PATH")