mirror of
https://github.com/bettercap/bettercap
synced 2025-07-30 11:40:33 -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_windows.go
Normal file
44
routing/update_windows.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(`^.+\d+\s+([^\s]+)\s+\d+\s+(.+)$`)
|
||||
|
||||
func update() ([]Route, error) {
|
||||
table = make([]Route, 0)
|
||||
|
||||
for ip, inet := range map[RouteType]string{IPv4: "ipv4", IPv6: "ipv6"} {
|
||||
output, err := core.Exec("netsh", []string{"interface", inet, "show", "route"})
|
||||
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 == 3 {
|
||||
route := Route{
|
||||
Type: ip,
|
||||
Destination: matches[1],
|
||||
Device: matches[2],
|
||||
}
|
||||
|
||||
if route.Destination == "0.0.0.0/0" || route.Destination == "::/0" {
|
||||
route.Default = true
|
||||
route.Gateway = route.Device
|
||||
route.Device = ""
|
||||
}
|
||||
|
||||
table = append(table, route)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return table, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue