mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 10:46:57 -07:00
Merge pull request #439 from rhaidiz/master
Add option to manually specify the gateway
This commit is contained in:
commit
17952a3904
3 changed files with 23 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/bettercap/bettercap/core"
|
||||
|
@ -48,3 +49,19 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
|||
Debug("FindGateway(%s): nothing found :/", iface.Name())
|
||||
return nil, ErrNoGateway
|
||||
}
|
||||
|
||||
func GatewayProvidedByUser(iface *Endpoint, gateway string) (*Endpoint, error) {
|
||||
Debug("GatewayProvidedByUser(%s) [cmd=%v opts=%v parser=%v]", gateway, IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
||||
if IPv4Validator.MatchString(gateway) {
|
||||
Debug("valid gateway ip %s",gateway)
|
||||
ifName := iface.Name()
|
||||
// we have the address, now we need its mac
|
||||
mac, err := ArpLookup(ifName, gateway, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Debug("gateway is %s[%s]", gateway, mac)
|
||||
return NewEndpoint(gateway, mac), nil
|
||||
}
|
||||
return nil, fmt.Errorf("Provided gateway %s not a valid IPv4 address! Revert to find default gateway.",gateway)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue