Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which network adapter is connected to the internet

I'm writing a program in C# that needs to monitor the amount of internet bandwidth currently in use so it can do a background upload when the internet usage is low. How can I automatically determine which network adapter is the one connected to the internet?

like image 989
Telanor Avatar asked Jan 31 '10 19:01

Telanor


People also ask

How do I know what my WiFi adapter is called?

Right-click the wireless adapter and select Properties. Click the Driver tab to see the wireless adapter property sheet. The Wi-Fi driver version number is listed in the Driver Version field.

How do I know if my network adapter is connected?

Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top.


2 Answers

I ended up following a link to MSDN when I was reading this page where I found the GetBestInterface function. I was able to use that to find the adapter thats connected to the internet

like image 191
Telanor Avatar answered Nov 14 '22 23:11

Telanor


Examine the routing table and look for the interfaces that have a default route (a route to 0.0.0.0) - that's your interface(s) that are connected to the wider world (if any).

like image 45
caf Avatar answered Nov 14 '22 22:11

caf