net_gateway_android.go 568 B

123456789101112131415161718192021222324252627
  1. package network
  2. import (
  3. "github.com/bettercap/bettercap/core"
  4. "github.com/evilsocket/islazy/str"
  5. )
  6. // Hi, i'm Android and my mum said I'm special.
  7. func FindGateway(iface *Endpoint) (*Endpoint, error) {
  8. output, err := core.Exec("getprop", []string{"net.dns1"})
  9. if err != nil {
  10. return nil, err
  11. }
  12. gw := str.Trim(output)
  13. if IPv4Validator.MatchString(gw) {
  14. // we have the address, now we need its mac
  15. mac, err := ArpLookup(iface.Name(), gw, false)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return NewEndpoint(gw, mac), nil
  20. }
  21. return nil, ErrNoGateway
  22. }