c# - Identification of active network card and get Default Gateway -
this question has answer here:
- get default gateway 7 answers
how identification of active network card , default gateway?

the following code gives 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; 
Comments
Post a Comment