c# - Identification of active network card and get Default Gateway -


this question has answer here:

how identification of active network card , default gateway?

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

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

Popular posts from this blog

c++ - protocol buffers - generate NON-inline accessors -

c# - issue attaching/adding an entity object which is detached from the DB Context? -