How do I get the identification of the active network card and get the default gateway?
Asked
Active
Viewed 4,838 times
1
-
What do you mean by indentification of active network card? – Martijn van Put Jul 31 '13 at 17:31
-
2http://stackoverflow.com/questions/13634868/get-the-default-gateway and http://stackoverflow.com/questions/3457119/how-to-get-default-nic-connection-name – Jeroen Vannevel Jul 31 '13 at 17:32
1 Answers
3
The following code gives you the first Default Gateway:
NetworkInterface card = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault();
if (card == null)
return null;
GatewayIPAddressInformation address = card.GetIPProperties().GatewayAddresses.FirstOrDefault();
if (address == null)
return null;
return address.Address;

Martijn van Put
- 3,293
- 18
- 17
-
-
In the windows TCP/IP 4 Properties you can press the "Advanced" button. Then you can add multiple "Default gateway's". – Martijn van Put Mar 12 '14 at 21:05