1

How do I get the identification of the active network card and get the default gateway?

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

hopper
  • 13,060
  • 7
  • 49
  • 53

1 Answers1

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