【发布时间】:2020-06-16 13:59:34
【问题描述】:
如何从禁用或断开连接的网络适配器(接口)获取默认网关(路由)及其指标?
与使用“netsh int ip show address”或“route print”或“netsh interface ip show route”的结果相同,其持久性路由:
还有
- WMI 类 Win32_NetworkAdapterConfiguration 仅适用于已启用和已连接的适配器:
string[] gateways = (string[]) objMO["DefaultIPGateway"]; UInt16[] gatewaysMetrics = (UInt16[]) objMO["GatewayCostMetric"];
- System.Net.NetworkInformation.NetworkInterface 类适用于断开连接的适配器,但只能获得没有指标的网关 Ips:
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();
- GetIpForwardTable 也只为连接的接口获取它。
如何获取断开的接口,如上面的命令?
还有其他方法吗?
【问题讨论】:
标签: c# c++ networking routes metrics