2023-06-09 18:27:09 +02:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package routemanager
|
2023-06-09 19:15:39 +02:00
|
|
|
|
|
|
|
import (
|
2023-06-12 12:16:00 +02:00
|
|
|
"fmt"
|
2023-06-12 11:43:18 +02:00
|
|
|
"net"
|
2023-06-09 19:15:39 +02:00
|
|
|
"net/netip"
|
|
|
|
|
2023-06-09 19:17:26 +02:00
|
|
|
"github.com/yusufpapurcu/wmi"
|
2023-06-09 19:15:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Win32_IP4RouteTable struct {
|
2023-06-12 11:06:49 +02:00
|
|
|
Destination string
|
|
|
|
Mask string
|
|
|
|
NextHop string
|
2023-06-09 19:15:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func existsInRouteTable(prefix netip.Prefix) (bool, error) {
|
|
|
|
var routes []Win32_IP4RouteTable
|
2023-06-12 11:06:49 +02:00
|
|
|
query := "SELECT Destination, Mask, NextHop FROM Win32_IP4RouteTable"
|
2023-06-09 19:15:39 +02:00
|
|
|
|
|
|
|
err := wmi.Query(query, &routes)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, route := range routes {
|
2023-06-12 14:56:30 +02:00
|
|
|
fmt.Println(routes)
|
2023-06-12 11:43:18 +02:00
|
|
|
ip := net.ParseIP(route.Mask)
|
2023-06-12 12:49:21 +02:00
|
|
|
ip = ip.To4()
|
|
|
|
mask := net.IPv4Mask(ip[0], ip[1], ip[2], ip[3])
|
2023-06-12 11:43:18 +02:00
|
|
|
cidr, _ := mask.Size()
|
2023-06-12 15:26:28 +02:00
|
|
|
if route.Destination == prefix.Addr().String() && cidr == prefix.Bits() && false {
|
2023-06-12 11:43:18 +02:00
|
|
|
return true, nil
|
|
|
|
}
|
2023-06-09 19:15:39 +02:00
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|