c#使用ManagedWifi查看當(dāng)前Wifi信號(hào)并選擇wifi的示例
使用ManagedWifi查看當(dāng)前Wifi信號(hào)并選擇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轉(zhuǎn)化成字符串
/// </summary>
static string GetStringForSSID(Wlan.Dot11Ssid ssid)
{
return Encoding.UTF8.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
}
/// <summary>
/// 枚舉所有無線設(shè)備接收到的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>
/// 字符串轉(zhuǎn)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); //默認(rèn)是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;
}
}
```
調(diào)用鏈接CMCC
===
```
WifiManager wm = new WifiManager();
wm.ConnectToCMCC();
相關(guān)文章
C#判斷一個(gè)類是否實(shí)現(xiàn)了某個(gè)接口3種實(shí)現(xiàn)方法
這篇文章主要介紹了C#判斷一個(gè)類是否實(shí)現(xiàn)了某個(gè)接口3種實(shí)現(xiàn)方法,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-06-06c# 實(shí)現(xiàn)計(jì)時(shí)器功能
這篇文章主要介紹了c# 實(shí)現(xiàn)計(jì)時(shí)器功能的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-12-12C#創(chuàng)建數(shù)據(jù)庫及附加數(shù)據(jù)庫的操作方法
這篇文章主要介紹了C#創(chuàng)建數(shù)據(jù)庫及附加數(shù)據(jù)庫的操作方法,涉及C#針對(duì)數(shù)據(jù)庫常見的創(chuàng)建、添加、連接等操作技巧,需要的朋友可以參考下2016-06-06C# TreeView無限目錄樹實(shí)現(xiàn)方法
這篇文章主要介紹了C# TreeView無限目錄樹實(shí)現(xiàn)方法,實(shí)例分析了TreeView節(jié)點(diǎn)操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06C#中使用ADOMD.NET查詢多維數(shù)據(jù)集的實(shí)現(xiàn)方法
這篇文章主要介紹了C#中使用ADOMD.NET查詢多維數(shù)據(jù)集的實(shí)現(xiàn)方法,詳細(xì)講述了C#中使用ADOMD.NET查詢多維數(shù)據(jù)集的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下2014-10-10