How do I uniquely identify only network connections that are *not* VPN connections?
See the question and my original answer on StackOverflowFrom an INetwork instance, you can get the list of connections (INetworkConnections instances) using the GetNetworkConnections method.
Then, using the INetworkConnection::GetAdapterId method, you can get a Guid that represent the adapter Id. The adapter Id in fact matches the NetworkInterface.Id Property (it's a string, but you can convert it to a Guid).
Here is a sample console app that dumps all network and their connections, and interface properties (type, name, etc.):
class Program
{
static void Main(string[] args)
{
var mgr = new NetworkListManager();
foreach (INetwork network in mgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_ALL))
{
Console.WriteLine("Network: " + network.GetName());
foreach (INetworkConnection conn in network.GetNetworkConnections())
{
Console.WriteLine(" Adapter Id: " + conn.GetAdapterId());
var ni = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i => new Guid(i.Id) == conn.GetAdapterId());
Console.WriteLine(" Interface: " + ni.Name);
Console.WriteLine(" Type: " + ni.NetworkInterfaceType);
}
}
}
}