mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 15:46:59 -07:00
fix: refactored routing logic (fixes #701)
This commit is contained in:
parent
88a83192ef
commit
43a93fd866
11 changed files with 202 additions and 80 deletions
44
routing/update_darwin.go
Normal file
44
routing/update_darwin.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"github.com/bettercap/bettercap/core"
|
||||
"github.com/evilsocket/islazy/str"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var parser = regexp.MustCompile(`^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+).*$`)
|
||||
|
||||
func update() ([]Route, error) {
|
||||
table = make([]Route, 0)
|
||||
|
||||
output, err := core.Exec("netstat", []string{"-n", "-r"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
if line = str.Trim(line); len(line) > 0 {
|
||||
matches := parser.FindStringSubmatch(line)
|
||||
if num := len(matches); num == 5 && matches[1] != "Destination" {
|
||||
route := Route{
|
||||
Destination: matches[1],
|
||||
Gateway: matches[2],
|
||||
Flags: matches[3],
|
||||
Device: matches[4],
|
||||
Default: matches[1] == "default",
|
||||
}
|
||||
|
||||
if strings.ContainsRune(route.Destination, '.') || strings.ContainsRune(route.Gateway, '.') {
|
||||
route.Type = IPv4
|
||||
} else {
|
||||
route.Type = IPv6
|
||||
}
|
||||
|
||||
table = append(table, route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return table, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue