mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
new: added debug callback to the network package
This commit is contained in:
parent
058a6865ff
commit
e50eaad7e6
3 changed files with 18 additions and 0 deletions
7
network/debug.go
Normal file
7
network/debug.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package network
|
||||
|
||||
type DebugFunc func(format string, args ...interface{})
|
||||
|
||||
var Debug = func(format string, args ...interface{}) {
|
||||
|
||||
}
|
|
@ -9,18 +9,24 @@ import (
|
|||
)
|
||||
|
||||
func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
||||
Debug("FindGateway(%s) [cmd=%v opts=%v parser=%v]", iface.Name(), IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
||||
|
||||
output, err := core.Exec(IPv4RouteCmd, IPv4RouteCmdOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Debug("FindGateway(%s) output:\n%s", iface.Name(), output)
|
||||
|
||||
ifName := iface.Name()
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
if strings.Contains(line, ifName) {
|
||||
m := IPv4RouteParser.FindStringSubmatch(line)
|
||||
if len(m) == IPv4RouteTokens {
|
||||
Debug("FindGateway(%s) line '%s' matched with %v", iface.Name(), line, m)
|
||||
return IPv4RouteIsGateway(ifName, m, func(gateway string) (*Endpoint, error) {
|
||||
if gateway == iface.IpAddress {
|
||||
Debug("gateway is the interface")
|
||||
return iface, nil
|
||||
} else {
|
||||
// we have the address, now we need its mac
|
||||
|
@ -28,6 +34,7 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Debug("gateway is %s[%s]", gateway, mac)
|
||||
return NewEndpoint(gateway, mac), nil
|
||||
}
|
||||
})
|
||||
|
|
|
@ -209,6 +209,10 @@ func (s *Session) Register(mod Module) error {
|
|||
func (s *Session) Start() error {
|
||||
var err error
|
||||
|
||||
network.Debug = func(format string, args ...interface{}) {
|
||||
s.Events.Log(log.DEBUG, format, args...)
|
||||
}
|
||||
|
||||
// make sure modules are always sorted by name
|
||||
sort.Slice(s.Modules, func(i, j int) bool {
|
||||
return s.Modules[i].Name() < s.Modules[j].Name()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue