mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
ffb060db16
commit
4cfcaf1c59
2 changed files with 15 additions and 16 deletions
|
@ -271,3 +271,18 @@ func ActivateInterface(name string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
// we have the address, now we need its mac
|
||||
if mac, err := ArpLookup(iface.Name(), gateway, false); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/bettercap/bettercap/core"
|
||||
|
@ -49,18 +48,3 @@ 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)
|
||||
// we have the address, now we need its mac
|
||||
if mac, err := ArpLookup(iface.Name(), gateway, false); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
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