Network List Manager API wrapped for .NET

DZone 's Guide to

Network List Manager API wrapped for .NET

· ·
Free Resource

One important feature in some of the modern application is the ability to interact with networks of various kinds. However, to get the information directly for a local network (the one the computer is connected to) some extensive API work is required. Windows API Code Pack (WACP) for .NET Framework wraps this API in a set of classes that can be used from a managed application, therefore the developer won’t have to use the system API directly.

The entire Network List Manager API in a managed application with WACP is based on the NetworkListManager class. The hierarchy of properties and methods is outlined below:

Via this class, the developer can access the current registered networks (related to the local machine). For example, here is how to get a collection of networks:

NetworkCollection nCollection = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All);

Note that I am querying all networks. NetworkConnectivityLevels can also be Connected or Disconnected. The resulting collection will represent the set of networks registered on the current machine, that also expose a set of properties. Those are outlined below for the Network class:

The developer can easily iterate through the networks in the collection to read the properties:

foreach (Network net in nCollection)


Now, you might be wondering – what is the NetworkId property used for. If you get the network GUID, you can later on query that specific network by calling something similar to this:

Network net = NetworkListManager.GetNetwork(networkID);

Notice the fact that there are two bool properties that are often requested in various applications. Verifying whether a network is generally connected or connected to Internet required is performed by manually checking for the availability of a web resource. This isn’t really a big issue if there is a single network registered, however, if there are more than 1 networks installed, checking each one for connectivity status can become quite complicated. By using the NLM API wrapper the developer can easily track this property for multiple networks, if those are present.

A similar process is applied to connections – the NetworkListManager is able to pick up a list of registered connections or one single connection, if the proper GUID is passed, although those are exposing a different set of properties.

The network IPs are not determined with the help of this wrapper, so the need in direct API calls and web service access is still needed to perform this specific task.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}