From 69e91d3a135d987734ba56100ea5ddbadb0eb041 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 25 Feb 2018 03:01:03 +0100 Subject: [PATCH] fix: trying to fix gateway detection on android --- network/net.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/network/net.go b/network/net.go index 3d7baedb..cffcf9c4 100644 --- a/network/net.go +++ b/network/net.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "regexp" + "runtime" "strconv" "strings" @@ -148,11 +149,13 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) { return nil, err } + isAndroid := runtime.GOOS == "android" + for _, line := range strings.Split(output, "\n") { m := IPv4RouteParser.FindStringSubmatch(line) if len(m) == IPv4RouteTokens { return IPv4RouteIsGateway(iface.Name(), m, func(gateway string) (*Endpoint, error) { - if gateway == iface.IpAddress { + if gateway == iface.IpAddress && isAndroid == false { return iface, nil } else { // 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.") }