misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-02-25 03:32:59 +01:00
commit e6bd5a9584
3 changed files with 70 additions and 45 deletions

View file

@ -0,0 +1,32 @@
package net
import (
"errors"
"fmt"
"net"
"regexp"
"runtime"
"strconv"
"strings"
"github.com/bettercap/bettercap/core"
)
func FindGateway(iface *Endpoint) (*Endpoint, error) {
output, err = core.Exec("getprop", []string{"net.dns1"})
if err != nil {
return nil, err
}
gw := core.Trim(output)
if IPv4Validator.MatchString(gw) {
// we have the address, now we need its mac
mac, err := ArpLookup(iface.Name(), gw, false)
if err != nil {
return nil, err
}
return NewEndpoint(gateway, mac), nil
}
return nil, ErrNoGateway
}