Reputation: 41
How get default gateways (routes) and their metrics from disabled or disconnected network adapters (interfaces) ?
same as result using "netsh int ip show address" or "route print" or "netsh interface ip show route", its persistence routes:
also
string[] gateways = (string[]) objMO["DefaultIPGateway"]; UInt16[] gatewaysMetrics = (UInt16[]) objMO["GatewayCostMetric"];
NetworkInterface nic = NetworkInterface.GetAllNetworkInterfaces().Where(e => e.Description == comboBoxInterface.Text).FirstOrDefault(); var nicProperties = nic.GetIPProperties(); var gateways = nicProperties.GatewayAddresses.Select(x => x.Address.ToString()).ToList();
How get it for disconnected interfaces, as in above commands?
Any other ways ?
Upvotes: 1
Views: 627
Reputation: 41
Resolved using WMI:
ObjectQuery query = new ObjectQuery("SELECT NextHop, Metric1 FROM Win32_IP4RouteTable WHERE Destination='0.0.0.0' AND Metric1<>0 AND InterfaceIndex=" + selectedNetInterfaceIndex);
but next question how do it using API ?
Upvotes: 1