1

如何获取活动网卡的标识并获取默认网关?

http://s4.picofile.com/file/7871762682/Default_Gateway.png

4

1 回答 1

3

以下代码为您提供了第一个默认网关:

 NetworkInterface card = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault();
 if (card == null)
    return null;
 GatewayIPAddressInformation address = card.GetIPProperties().GatewayAddresses.FirstOrDefault();
 if (address == null)
     return null;

 return address.Address;
于 2013-07-31T17:34:51.217 回答