简体   繁体   English

Windows forms c# 通过 BSSID 连接到特定接入点

[英]Windows forms c# connect to specific accesspoint by BSSID

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.我有一个 windows 表格,写成 c#。我制作了一个列表视图,用于查找并汇总它可以检测到的每个 wifi.network,提供 SSID、BSSID 等。

I'm using ManagedNativeWifi to get all the information about the wifi.networks.我正在使用 ManagedNativeWifi 获取有关 wifi.networks 的所有信息。 I'm looking for a way to connect to a specific accesspoint, by the BSSID of the accesspoint.我正在寻找一种通过访问点的 BSSID 连接到特定访问点的方法。

Connecting with the specified SSID is possible by using this code:使用此代码可以连接指定的 SSID:

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?但是有没有办法连接 BSSID 而不是 SSID?

For anyone coming across this post, I managed to make it work by using the ManagedNativeWifi api.对于看到这篇文章的任何人,我设法通过使用 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));
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM