SkillAgentSearch skills...

ManagedNativeWifi

A managed implementation of Native Wifi API

Install / Use

/learn @emoacht/ManagedNativeWifi
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Managed Native Wifi

ManagedNativeWifi is a managed implementation of [Native Wifi][1] API. It provides functionality to manage wireless networks, interfaces and profiles.

Requirements

This library works on Windows and compatible with:

.NET 8.0|.NET Standard 2.0 (including .NET Framework 4.6.1) -|-

On Windows 11 (24H2) or newer, some methods require user's permission to access location information. Without the permission, UnauthorizedAccessException will be thrown. This permission can be set in Privacy & security > Location settings.

Download

NuGet: [ManagedNativeWifi][2]

Methods

Available methods including asynchronous ones based on TAP.

| Method | Description | |---------------------------------|----------------------------------------------------------------------------------------------------| | EnumerateInterfaces | Enumerates wireless interface information. | | EnumerateInterfaceConnections | Enumerates wireless interface and related connection information. | | ScanNetworksAsync | Asynchronously requests wireless interfaces to scan (rescan) wireless LANs. | | EnumerateAvailableNetworkSsids | Enumerates SSIDs of available wireless LANs. | | EnumerateConnectedNetworkSsids | Enumerates SSIDs of connected wireless LANs. | | EnumerateAvailableNetworks | Enumerates wireless LAN information on available networks. | | EnumerateAvailableNetworkGroups | Enumerates wireless LAN information on available networks and group of associated BSS networks. | | EnumerateBssNetworks | Enumerates wireless LAN information on BSS networks. | | GetCurrentConnection | Gets wireless connection information (connected wireless LAN only) | | GetRssi | Gets RSSI (connected wireless LAN only). | | GetRealtimeConnetionQuality | Gets wireless connection quality information (connected wireless LAN only, Windows 11 24H2 only) | | EnumerateProfileNames | Enumerates wireless profile names in preference order. | | EnumerateProfiles | Enumerates wireless profile information in preference order. | | EnumerateProfileRadios | Enumerates wireless profile and related radio information in preference order. | | SetProfile | Sets (add or overwrite) the content of a specified wireless profile. | | SetProfilePosition | Sets the position of a specified wireless profile in preference order. | | SetProfileEapXmlUserData | Sets (add or overwirte) the EAP user credentials for a specified wireless profile. | | RenameProfile | Renames a specified wireless profile. | | DeleteProfile | Deletes a specified wireless profile. | | ConnectNetwork | Attempts to connect to the wireless LAN associated to a specified wireless profile. | | ConnectNetworkAsync | Asynchronously attempts to connect to the wireless LAN associated to a specified wireless profile. | | DisconnectNetwork | Disconnects from the wireless LAN associated to a specified wireless interface. | | DisconnectNetworkAsync | Asynchronously disconnects from the wireless LAN associated to a specified wireless interface. | | GetRadio | Gets wireless interface radio information of a specified wireless interface. | | TurnOnRadio | Turns on the radio of a specified wireless interface (software radio state only). | | TurnOffRadio | Turns off the radio of a specified wireless interface (software radio state only). | | IsAutoConfig | Checks if automatic configuration of a specified wireless interface is enabled. |

Properties

| Property | Description | |--------------------|-------------------------------------------------------| | ThrowsOnAnyFailure | Whether to throw an exception when any failure occurs |

Usage

To check SSIDs of currently available wireless LANs, call EnumerateAvailableNetworkSsids method.

public static IEnumerable<string> EnumerateNetworkSsids()
{
    return NativeWifi.EnumerateAvailableNetworkSsids()
        .Select(x => x.ToString()); // UTF-8 string representation
}

In general, a SSID is represented by a UTF-8 string but it is not guaranteed. So if ToString method seems not to produce a valid value, try ToBytes method instead.

To check SSID, signal quality or other information on currently available wireless LANs, call EnumerateAvailableNetworks method.

public static IEnumerable<(string ssidString, int signalQuality)>
    EnumerateNetworkSsidsAndSignalQualities()
{
    return NativeWifi.EnumerateAvailableNetworks()
        .Select(x => (x.Ssid.ToString(), x.SignalQuality));
}

To connect to a wireless LAN, call ConnectNetworkAsync asynchronous method.

public static async Task<bool> ConnectAsync()
{
    var availableNetwork = NativeWifi.EnumerateAvailableNetworks()
        .Where(x => !string.IsNullOrWhiteSpace(x.ProfileName))
        .OrderByDescending(x => x.SignalQuality)
        .FirstOrDefault();

    if (availableNetwork is null)
        return false;

    return await NativeWifi.ConnectNetworkAsync(
        interfaceId: availableNetwork.InterfaceInfo.Id,
        profileName: availableNetwork.ProfileName,
        bssType: availableNetwork.BssType,
        timeout: TimeSpan.FromSeconds(10));
}

This method returns true if successfully connected to the wireless LAN in contrast to its synchronous sibling, ConnectNetwork method, returns true if the request for the connection succeeds and doesn't indicate the result.

To refresh currently available wireless LANs, call ScanNetworksAsync method.

public static Task RefreshAsync()
{
    return NativeWifi.ScanNetworksAsync(timeout: TimeSpan.FromSeconds(10));
}

This method requests wireless interfaces to scan wireless LANs in parallel. The timeout should be ideally no more than 4 seconds, but it can vary depending on the situation.

If you want to avoid disrupting existing wireless connections, you can use ScanNetworksAsync overload method with ScanMode.OnlyNotConnected.

public static Task RefreshNotConnectedAsync()
{
    return NativeWifi.ScanNetworksAsync(
        mode: ScanMode.OnlyNotConnected,
        null,
        null,
        timeout: TimeSpan.FromSeconds(10),
        CancellationToken.None);
}

Please note that if all wireless interfaces are connected, naturally nothing will happen.

To delete an existing wireless profile, use DeleteProfile method. Please note that a profile name is case-sensitive.

public static bool DeleteProfile(string profileName)
{
    var targetProfile = NativeWifi.EnumerateProfiles()
        .Where(x => profileName.Equals(x.Name, StringComparison.Ordinal))
        .FirstOrDefault();

    if (targetProfile is null)
        return false;

    return NativeWifi.DeleteProfile(
        interfaceId: targetProfile.InterfaceInfo.Id,
        profileName: profileName);
}

To check wireless LAN channels that are already used by surrounding access points, call EnumerateBssNetworks method and filter the results by RSSI.

public static IEnumerable<int> EnumerateNetworkChannels(int rssiThreshold)
{
    return NativeWifi.EnumerateBssNetworks()
        .Where(x => x.Rssi > rssiThreshold)
        .Select(x => x.Channel);
}

To turn on the radio of a wireless interface, check the current radio state by GetRadio method and then call TurnOnRadio method.

public static async Task<bool> TurnOnAsync()
{
    var targetInterface = NativeWifi.EnumerateInterfaces()
        .FirstOrDefault(x =>
        {
            var radioState = NativeWifi.GetRadio(x.Id)?.RadioStates.FirstOrDefault();
            if (radioState is null)
                return false;

            if (!radioState.IsHardwareOn) // Hardware radio state is off.
                return false;

            return !radioState.IsSoftwareOn; // Software radio state is off.
        });

    if (targetInterface is null)
        return false;

    try
    {
        return await Task.Run(() => NativeWifi.TurnOnRadio(targetInterface.Id));
    }
    catch (UnauthorizedAccessException)
    {
        return false;
    }
}

Please note that this method can only change software radio state and if hardware radio state is off (like hardware Wi-Fi switch is at off position), the radio cannot be turned on programatically.

To retrieve detailed information on wireless connections of connected wireless interfaces, you can use GetCurrentConnection, GetRssi, GetRealtimeConnectionQuality methods depending on your needs.

public static void ShowConnectedNetworkInformation()
{
    foreach (var interfaceId in NativeWifi.EnumerateInterfaces()
 
View on GitHub
GitHub Stars165
CategoryDevelopment
Updated18d ago
Forks50

Languages

C#

Security Score

100/100

Audited on Mar 16, 2026

No findings