mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
fix: fixed gateway regexp for macOS (closes #645)
This commit is contained in:
parent
6755d8c880
commit
9c3790764a
2 changed files with 4 additions and 5 deletions
|
@ -13,16 +13,15 @@ import (
|
|||
|
||||
const airPortPath = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
|
||||
|
||||
var IPv4RouteParser = regexp.MustCompile(`^([a-z]+)+\s+(\d+\.+\d+.\d.+\d)+\s+([a-zA-z]+)+\s+(\d+)+\s+(\d+)+\s+([a-zA-Z]+\d+)$`)
|
||||
var IPv4RouteTokens = 7
|
||||
var IPv4RouteParser = regexp.MustCompile(`([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+).*`)
|
||||
var IPv4RouteTokens = 5
|
||||
var IPv4RouteCmd = "netstat"
|
||||
var IPv4RouteCmdOpts = []string{"-n", "-r"}
|
||||
var WiFiChannelParser = regexp.MustCompile(`(?m)^.*Supported Channels: (.*)$`)
|
||||
|
||||
func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (*Endpoint, error)) (*Endpoint, error) {
|
||||
ifname2 := tokens[6]
|
||||
flags := tokens[3]
|
||||
|
||||
ifname2 := tokens[4]
|
||||
if ifname == ifname2 && flags == "UGSc" {
|
||||
gateway := tokens[2]
|
||||
return f(gateway)
|
||||
|
|
|
@ -25,7 +25,7 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
|||
for _, line := range strings.Split(output, "\n") {
|
||||
if line = str.Trim(line); strings.Contains(line, ifName) {
|
||||
m := IPv4RouteParser.FindStringSubmatch(line)
|
||||
if len(m) == IPv4RouteTokens {
|
||||
if len(m) >= IPv4RouteTokens {
|
||||
Debug("FindGateway(%s) line '%s' matched with %v", iface.Name(), line, m)
|
||||
return IPv4RouteIsGateway(ifName, m, func(gateway string) (*Endpoint, error) {
|
||||
if gateway == iface.IpAddress {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue