mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
commit
84846b11dc
2 changed files with 29 additions and 17 deletions
|
@ -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")
|
||||
|
|
|
@ -25,22 +25,30 @@ func Dot11Freq2Chan(freq int) int {
|
|||
return ((freq - 5035) / 5) + 7
|
||||
} else if freq >= 5875 && freq <= 5895 {
|
||||
return 177
|
||||
} else if freq >= 5955 && freq <= 7115 { // 6GHz
|
||||
return ((freq - 5955) / 5) + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func Dot11Chan2Freq(channel int) int {
|
||||
if channel <= 13 {
|
||||
return ((channel - 1) * 5) + 2412
|
||||
} else if channel == 14 {
|
||||
return 2484
|
||||
} else if channel <= 173 {
|
||||
return ((channel - 7) * 5) + 5035
|
||||
} else if channel == 177 {
|
||||
return 5885
|
||||
}
|
||||
|
||||
return 0
|
||||
if channel <= 13 {
|
||||
return ((channel - 1) * 5) + 2412
|
||||
} else if channel == 14 {
|
||||
return 2484
|
||||
} else if channel == 36 || channel == 40 || channel == 44 || channel == 48 ||
|
||||
channel == 52 || channel == 56 || channel == 60 || channel == 64 ||
|
||||
channel == 68 || channel == 72 || channel == 76 || channel == 80 ||
|
||||
channel == 100 || channel == 104 || channel == 108 || channel == 112 ||
|
||||
channel == 116 || channel == 120 || channel == 124 || channel == 128 ||
|
||||
channel == 132 || channel == 136 || channel == 140 || channel == 144 ||
|
||||
channel == 149 || channel == 153 || channel == 157 || channel == 161 ||
|
||||
channel == 165 || channel == 169 || channel == 173 || channel == 177 {
|
||||
return ((channel - 7) * 5) + 5035
|
||||
// 6GHz - Skipped 1-13 to avoid 2Ghz channels conflict
|
||||
} else if channel >= 17 && channel <= 253 {
|
||||
return ((channel - 1) * 5) + 5955
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type APNewCallback func(ap *AccessPoint)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue