以下程式碼是為了得知無線區域網路訊號強弱,而所寫出來的功能。
程式碼如下:
string sOutput = string.Empty;
AdapterCollection adapters = Networking.GetAdapters();
foreach (Adapter a in adapters)
{
if (a.IsWireless)
{
AccessPointCollection apc = a.NearbyAccessPoints;
IEnumerator ieap = apc.GetEnumerator();
while (ieap.MoveNext())
{
AccessPoint ap = (AccessPoint)ieap.Current;
string adapterName = "網路名稱:" + ap.Name;
string adapterChannel = "頻道:" + ap.Channel.ToString();
string macAddress = "MacAddress:" + BitConverter.ToString(ap.MacAddress);
string signalStrength = "訊號強弱:" + ap.SignalStrengthInDecibels.ToString() + "dB (" + ap.SignalStrength.ToString() + ")";
sOutput += string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", adapterName, adapterChannel, macAddress, signalStrength) + "\r\n\r\n";
}
}
else
{
sOutput += string.Format("無WiFi信號: {0} - {1}", a.Name, a.Type) + "\r\n\r\n";
}
}
textBox1.Text = sOutput + "作業結束!";
以上程式資料來源與要Input DLL檔皆在OpenNETCF 官方網站下載:http://www.opennetcf.com/
若有錯誤,煩請告知!
也可一起分享與討論,謝謝。
留言列表