mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
17952a3904
commit
a6e87618d4
2 changed files with 17 additions and 14 deletions
|
@ -53,15 +53,14 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
||||||
func GatewayProvidedByUser(iface *Endpoint, gateway string) (*Endpoint, error) {
|
func GatewayProvidedByUser(iface *Endpoint, gateway string) (*Endpoint, error) {
|
||||||
Debug("GatewayProvidedByUser(%s) [cmd=%v opts=%v parser=%v]", gateway, IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
Debug("GatewayProvidedByUser(%s) [cmd=%v opts=%v parser=%v]", gateway, IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
||||||
if IPv4Validator.MatchString(gateway) {
|
if IPv4Validator.MatchString(gateway) {
|
||||||
Debug("valid gateway ip %s",gateway)
|
Debug("valid gateway ip %s", gateway)
|
||||||
ifName := iface.Name()
|
|
||||||
// we have the address, now we need its mac
|
// we have the address, now we need its mac
|
||||||
mac, err := ArpLookup(ifName, gateway, false)
|
if mac, err := ArpLookup(iface.Name(), gateway, false); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
} else {
|
||||||
Debug("gateway is %s[%s]", gateway, mac)
|
Debug("gateway is %s[%s]", gateway, mac)
|
||||||
return NewEndpoint(gateway, mac), nil
|
return NewEndpoint(gateway, mac), nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Provided gateway %s not a valid IPv4 address! Revert to find default gateway.",gateway)
|
}
|
||||||
|
return nil, fmt.Errorf("Provided gateway %s not a valid IPv4 address! Revert to find default gateway.", gateway)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
"github.com/evilsocket/islazy/fs"
|
"github.com/evilsocket/islazy/fs"
|
||||||
"github.com/evilsocket/islazy/log"
|
"github.com/evilsocket/islazy/log"
|
||||||
|
"github.com/evilsocket/islazy/ops"
|
||||||
"github.com/evilsocket/islazy/str"
|
"github.com/evilsocket/islazy/str"
|
||||||
"github.com/evilsocket/islazy/tui"
|
"github.com/evilsocket/islazy/tui"
|
||||||
)
|
)
|
||||||
|
@ -226,15 +227,18 @@ func (s *Session) Start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *s.Options.Gateway != "" {
|
||||||
if s.Gateway, err = network.GatewayProvidedByUser(s.Interface, *s.Options.Gateway); err != nil {
|
if s.Gateway, err = network.GatewayProvidedByUser(s.Interface, *s.Options.Gateway); err != nil {
|
||||||
level := log.WARNING
|
s.Events.Log(log.WARNING, "%s", err.Error())
|
||||||
if s.Interface.IsMonitor() {
|
s.Gateway, err = network.FindGateway(s.Interface)
|
||||||
level = log.DEBUG
|
|
||||||
}
|
}
|
||||||
s.Events.Log(level, "%s", err.Error())
|
} else {
|
||||||
if s.Gateway, err = network.FindGateway(s.Interface); err != nil {
|
s.Gateway, err = network.FindGateway(s.Interface)
|
||||||
s.Events.Log(level, "%s", err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
level := ops.Ternary(s.Interface.IsMonitor(), log.DEBUG, log.WARNING).(log.Verbosity)
|
||||||
|
s.Events.Log(level, "%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Gateway == nil || s.Gateway.IpAddress == s.Interface.IpAddress {
|
if s.Gateway == nil || s.Gateway.IpAddress == s.Interface.IpAddress {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue