You can use IsNetworkAlive (). Although technically it does not check the status of the link, it is probably better since it can also detect wireless and dial-up connections. Here is an example:
using System.Runtime.InteropServices; class Program { [DllImport("sensapi.dll")] static extern bool IsNetworkAlive(out int flags); static void Main(string[] args) { int flags; bool connected = IsNetworkAlive(out flags); } }
The flags parameter returns whether the connection to the Internet or only to the local network. I'm not 100% sure how he knows, but I would argue that he is just looking to see if there is a set of default gateways.
Jeff mc
source share