views:

423

answers:

4

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?

+1  A: 

You can use WMI to query all the adapters and see which one is connected.
This article shows you how to do it in VB.Net (very easily transferable to C#).

Traveling Tech Guy
+2  A: 

See here for a similar question on how to monitor the bandwidth used, in VB.NET, but the philosophy is the same! Here is another question that is the fastest way of checking for internet connection.

Hope this helps, Best regards, Tom.

tommieb75
+1  A: 

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

Telanor
A: 

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).

caf