mirror of
https://github.com/bettercap/bettercap
synced 2025-07-05 20:42:09 -07:00
Update net_linux.go
Code Review
This commit is contained in:
parent
4320b98e80
commit
dd05670e1f
1 changed files with 9 additions and 5 deletions
|
@ -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")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue