mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
fix: trying to fix gateway detection on android
This commit is contained in:
parent
5509a58e52
commit
69e91d3a13
1 changed files with 19 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -148,11 +149,13 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAndroid := runtime.GOOS == "android"
|
||||||
|
|
||||||
for _, line := range strings.Split(output, "\n") {
|
for _, line := range strings.Split(output, "\n") {
|
||||||
m := IPv4RouteParser.FindStringSubmatch(line)
|
m := IPv4RouteParser.FindStringSubmatch(line)
|
||||||
if len(m) == IPv4RouteTokens {
|
if len(m) == IPv4RouteTokens {
|
||||||
return IPv4RouteIsGateway(iface.Name(), m, func(gateway string) (*Endpoint, error) {
|
return IPv4RouteIsGateway(iface.Name(), m, func(gateway string) (*Endpoint, error) {
|
||||||
if gateway == iface.IpAddress {
|
if gateway == iface.IpAddress && isAndroid == false {
|
||||||
return iface, nil
|
return iface, nil
|
||||||
} else {
|
} else {
|
||||||
// we have the address, now we need its mac
|
// we have the address, now we need its mac
|
||||||
|
@ -166,5 +169,20 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isAndroid {
|
||||||
|
output, err = core.Exec("getprop", []string{"net.dns1"})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
gateway := core.Trim(output)
|
||||||
|
// we have the address, now we need its mac
|
||||||
|
mac, err := ArpLookup(iface.Name(), gateway, false)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s\n", err)
|
||||||
|
}
|
||||||
|
return NewEndpoint(gateway, mac), nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("Could not detect the gateway.")
|
return nil, fmt.Errorf("Could not detect the gateway.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue