如何获取活动网卡的标识并获取默认网关?
答案 0 :(得分: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;