国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#使用ManagedWifi查看當前Wifi信號并選擇wifi的示例

2020-01-24 02:43:24
字體:
來源:轉載
供稿:網友

使用ManagedWifi查看當前Wifi信號并選擇wifi

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NativeWifi;

namespace WifiExample
{
    class WifiManager
    {
        //CMCC的WIFISSID
        public WIFISSID cmccWifiSSID;

        public WifiManager()
        {
            ScanSSID();
        }

        /// <summary>
        /// 將SSID轉化成字符串
        /// </summary>
        static string GetStringForSSID(Wlan.Dot11Ssid ssid)
        {
            return Encoding.UTF8.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
        }

        /// <summary> 
        /// 枚舉所有無線設備接收到的SSID 
        /// </summary> 
        public void ScanSSID()
        {
            WlanClient client = new WlanClient();
            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                // Lists all networks with WEP security 
                Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                {
                    WIFISSID targetSSID = new WIFISSID();
                    targetSSID.wlanInterface = wlanIface;
                    targetSSID.wlanSignalQuality = (int)network.wlanSignalQuality;
                    targetSSID.SSID = GetStringForSSID(network.dot11Ssid);
                    targetSSID.dot11DefaultAuthAlgorithm = network.dot11DefaultAuthAlgorithm.ToString();
                    targetSSID.dot11DefaultCipherAlgorithm = network.dot11DefaultCipherAlgorithm.ToString();
                    Console.WriteLine(targetSSID.SSID);
                    if (targetSSID.SSID.ToLower().Equals("cmcc"))
                    {
                        cmccWifiSSID = targetSSID;
                        return;
                    }
                }
            }
        } // EnumSSID 

        /// <summary> 
        /// 連接到CMCC
        /// </summary> 
        /// <param name="ssid"></param> 
        public void ConnectToCMCC()
        {
            // Connects to a known network with WEP security 
            string profileName = cmccWifiSSID.SSID; // this is also the SSID
            Console.WriteLine("profileName" + profileName);
            cmccWifiSSID.wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
        }

        /// <summary> 
        /// 字符串轉Hex 
        /// </summary> 
        /// <param name="str"></param> 
        /// <returns></returns> 
        public static string StringToHex(string str)
        {
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.Default.GetBytes(str); //默認是System.Text.Encoding.Default.GetBytes(str) 
            for (int i = 0; i < byStr.Length; i++)
            {
                sb.Append(Convert.ToString(byStr[i], 16));
            }

            return (sb.ToString().ToUpper());
        }

    } // Class WifiManager


    class WIFISSID
    {
        public string SSID = "NONE";
        public string dot11DefaultAuthAlgorithm = "";
        public string dot11DefaultCipherAlgorithm = "";
        public bool networkConnectable = true;
        public string wlanNotConnectableReason = "";
        public int wlanSignalQuality = 0;
        public WlanClient.WlanInterface wlanInterface = null;
    }

}
```


調用鏈接CMCC
===
```
WifiManager wm = new WifiManager();
wm.ConnectToCMCC();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亳州市| 兰溪市| 江安县| 报价| 博罗县| 沙洋县| 富平县| 外汇| 莫力| 台东市| 朝阳县| 洞头县| 东源县| 大悟县| 临邑县| 漯河市| 新邵县| 长葛市| 平定县| 宕昌县| 荔浦县| 安西县| 通城县| 土默特右旗| 庐江县| 囊谦县| 涡阳县| 清远市| 普定县| 进贤县| 剑阁县| 桃园县| 梨树县| 怀远县| 永顺县| 赣州市| 大邑县| 重庆市| 衡水市| 和平区| 元氏县|