Wifi 5GHz support added to wifi.recon

This commit is contained in:
Matrix86 2018-02-20 12:40:55 +01:00
commit 813561cbda
7 changed files with 70 additions and 21 deletions

View file

@ -1,9 +1,12 @@
package network
import (
"bufio"
"fmt"
"net"
"regexp"
"strconv"
"strings"
"github.com/evilsocket/bettercap-ng/core"
)
@ -13,6 +16,7 @@ var IPv4RouteParser = regexp.MustCompile("^(default|[0-9\\.]+)\\svia\\s([0-9\\.]
var IPv4RouteTokens = 4
var IPv4RouteCmd = "ip"
var IPv4RouteCmdOpts = []string{"route"}
var WiFiFreqParser = regexp.MustCompile("^\\s+Channel.([0-9]+)\\s+:\\s+([0-9\\.]+)\\s+GHz.*$")
func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (*Endpoint, error)) (*Endpoint, error) {
ifname2 := tokens[3]
@ -39,3 +43,23 @@ func SetInterfaceChannel(iface string, channel int) error {
}
return nil
}
func GetSupportedFrequencies(iface string) ([]int, error) {
freqs := make([]int, 0)
out, err := core.Exec("iwlist", []string{iface, "freq"})
if err != nil {
return freqs, err
} else if out != "" {
scanner := bufio.NewScanner(strings.NewReader(out))
for scanner.Scan() {
line := scanner.Text()
matches := WiFiFreqParser.FindStringSubmatch(line)
if matches != nil && len(matches) == 3 {
if freq, err := strconv.ParseFloat(matches[2], 64); err == nil {
freqs = append(freqs, int(freq*1000))
}
}
}
}
return freqs, nil
}