程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c#應用ManagedWifi檢查以後Wifi旌旗燈號並選擇wifi的示例

c#應用ManagedWifi檢查以後Wifi旌旗燈號並選擇wifi的示例

編輯:C#入門知識

c#應用ManagedWifi檢查以後Wifi旌旗燈號並選擇wifi的示例。本站提示廣大學習愛好者:(c#應用ManagedWifi檢查以後Wifi旌旗燈號並選擇wifi的示例)文章只能為提供參考,不一定能成為您想要的結果。以下是c#應用ManagedWifi檢查以後Wifi旌旗燈號並選擇wifi的示例正文


應用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();

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved