| 1 | package routingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/ |
| 2 | |
| 3 | import ( |
| 4 | "regexpscip-go gomod github.com/golang/go/src go1.16 regexp/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 6 | |
| 7 | "github.com/bettercap/bettercap/corescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/core`/" |
| 8 | "github.com/evilsocket/islazy/strscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/" |
| 9 | ) |
| 10 | |
| 11 | var ( |
| 12 | routeHeadingsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/routeHeadings. []string |
| 13 | whitespaceParserscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/whitespaceParser. = regexpscip-go gomod github.com/golang/go/src go1.16 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.16 regexp/MustCompile().(`\s+`) |
| 14 | ) |
| 15 | |
| 16 | func updatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/update().() ([]Routescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#, error) { |
| 17 | tablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/table. = make([]Routescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#, 0) |
| 18 | |
| 19 | output, err := corescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/core`/.Execscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/core`/Exec().("netstat", []string{"-r", "-n", "-4", "-6"}) |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | // because entries are separated by whitespace |
| 24 | output = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.16 strings/ReplaceAll().(output, "Next Hop", "Gateway") |
| 25 | |
| 26 | for _, line := range stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(output, "\n") { |
| 27 | if line = strscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/.Trimscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/Trim().(line); len(line) != 0 { |
| 28 | parts := whitespaceParserscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/whitespaceParser..Splitscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#Split().(line, -1) |
| 29 | if parts[0] == "Kernel" { |
| 30 | continue |
| 31 | } |
| 32 | |
| 33 | if parts[0] == "Destination" { |
| 34 | routeHeadingsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/routeHeadings. = parts |
| 35 | continue |
| 36 | } |
| 37 | |
| 38 | // skip line if no route headings found yet |
| 39 | if routeHeadingsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/routeHeadings. == nil { |
| 40 | continue |
| 41 | } |
| 42 | |
| 43 | route := Routescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#{} |
| 44 | for i, s := range parts { |
| 45 | switch routeHeadingsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/routeHeadings.[i] { |
| 46 | case "Destination": |
| 47 | route.Destinationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Destination. = s |
| 48 | break |
| 49 | case "Flag": |
| 50 | route.Flagsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Flags. = s |
| 51 | break |
| 52 | case "Flags": |
| 53 | route.Flagsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Flags. = s |
| 54 | break |
| 55 | case "Gateway": |
| 56 | route.Gatewayscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Gateway. = s |
| 57 | break |
| 58 | case "If": |
| 59 | route.Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Device. = s |
| 60 | break |
| 61 | case "Iface": |
| 62 | route.Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Device. = s |
| 63 | break |
| 64 | case "Netif": |
| 65 | route.Devicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Device. = s |
| 66 | break |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | route.Defaultscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Default. = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Containsscip-go gomod github.com/golang/go/src go1.16 strings/Contains().(route.Flagsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Flags., "G") |
| 71 | |
| 72 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ContainsRunescip-go gomod github.com/golang/go/src go1.16 strings/ContainsRune().(route.Destinationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Destination., '.') || stringsscip-go gomod github.com/golang/go/src go1.16 strings/.ContainsRunescip-go gomod github.com/golang/go/src go1.16 strings/ContainsRune().(route.Gatewayscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Gateway., '.') { |
| 73 | route.Typescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Type. = IPv4scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/IPv4. |
| 74 | } else { |
| 75 | route.Typescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/Route#Type. = IPv6scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/IPv6. |
| 76 | } |
| 77 | |
| 78 | tablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/table. = append(tablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/table., route) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return tablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/routing`/table., nil |
| 83 | } |