Windows forms c# connect to specific accesspoint by BSSID

438 Views Asked by At

I have a windows form written in c#. I've made a listview that finds and sums up every wifi network it can detect, giving the SSID, BSSID, and more.

I'm using ManagedNativeWifi to get all the information about the wifi networks. I'm looking for a way to connect to a specific accesspoint, by the BSSID of the accesspoint.

Connecting with the specified SSID is possible by using this code:

public static async Task<bool> ConnectAsync()
    {
        String SSID = "MyWiFiNetwork";
        String BSSID = "E2-B4-F7-F7-FD-F8".Replace("-", ":"); // Currently not used...
        var availableNetwork = NativeWifi.EnumerateAvailableNetworks()
            
            .Where(x => !string.IsNullOrWhiteSpace(x.ProfileName))
            .OrderByDescending(x => x.SignalQuality)
            .FirstOrDefault();

        if (availableNetwork is null)
            return false;

        return NativeWifi.ConnectNetwork(
            interfaceId: availableNetwork.Interface.Id,
            profileName: SSID,
            bssType: BssType.Infrastructure
            );  
    }

But instead of SSID, is there a way to connect with the BSSID?

1

There are 1 best solutions below

0
On

For anyone coming across this post, I managed to make it work by using the ManagedNativeWifi api.

public async Task<bool> ConnectAsync()
    {
        String BSSID = "MyWiFiNetwork";
        String SSID = "E2-B4-F7-F7-FD-F8".Replace("-", "").ToUpper();
        var availableNetwork = NativeWifi.EnumerateAvailableNetworks()
            .Where(x => !string.IsNullOrWhiteSpace(x.ProfileName))
            .OrderByDescending(x => x.SignalQuality)
            .FirstOrDefault();
        if (availableNetwork is null)
            return false;

        return NativeWifi.ConnectNetwork(
            interfaceId: availableNetwork.Interface.Id,
            profileName: SSID,
            bssType: BssType.Infrastructure, System.Net.NetworkInformation.PhysicalAddress.Parse(BSSID));
    }