0

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?

ILLUXN
  • 1
  • 1
  • WlanConnect() alows to connect to BSSIDs list (of course, the list may include just a single BSSID), However SSID is required any way. I have no idea how to do that with NativeWiFi you use but it is easy with WiFi Framework (https://www.btframework.com/wififramework.htm) – Mike Petrichenko Mar 06 '22 at 12:17
  • Thank you, I have access to both the SSID and the BSSID, so that shouldn't be a problem. I'll check out that framework and report back once I have a working solution :-) Edit: sadly enough it's a paid framework, so won't be using that :-( – ILLUXN Mar 06 '22 at 13:07

1 Answers1

0

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));
    }
ILLUXN
  • 1
  • 1