fix: trying to fix gateway detection on android

This commit is contained in:
evilsocket 2018-02-25 03:01:03 +01:00
commit 69e91d3a13

View file

@ -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.")
} }