mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-18 11:11:20 +01:00
41 lines
872 B
Go
41 lines
872 B
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package routemanager
|
|
|
|
import (
|
|
"fmt"
|
|
"net/netip"
|
|
|
|
"github.com/StackExchange/wmi"
|
|
)
|
|
|
|
type Win32_IP4RouteTable struct {
|
|
Destination string
|
|
Mask string
|
|
NextHop string
|
|
InterfaceIdx int
|
|
}
|
|
|
|
func existsInRouteTable(prefix netip.Prefix) (bool, error) {
|
|
var routes []Win32_IP4RouteTable
|
|
query := "SELECT Destination, Mask, NextHop, InterfaceIndex FROM Win32_IP4RouteTable"
|
|
|
|
err := wmi.Query(query, &routes)
|
|
if err != nil {
|
|
return true, err
|
|
}
|
|
|
|
fmt.Println("Destination Networks:")
|
|
for _, route := range routes {
|
|
fmt.Println("Destination :", route.Destination)
|
|
fmt.Println("Mask :", route.Mask)
|
|
// mask, _ := toIPAddr(m.Addrs[2])
|
|
// cidr, _ := net.IPMask(mask.To4()).Size()
|
|
// if route.Destination == prefix.Addr().String() && cidr == prefix.Bits() {
|
|
// return true, nil
|
|
// }
|
|
}
|
|
return false, nil
|
|
}
|