C#

[C#]NativeWifi를 이용한 무선랜 정보 얻어오기 예제

선영아 사랑해 2016. 2. 17. 11:28

주변에 있는 무선AP 정보 검색 및 감도 확인 할 수 있는 예제코드입니다.


managedwifi-1.1.zip


첨부파일에서 Interop.cs, WlanApi.cs 파일을 기존항목 추가 후 아래의 작업하면 됩니다.


using NativeWifi;


private void button2_Click(object sender, EventArgs e)
{
    var wlanClient = new WlanClient();

    foreach (WlanClient.WlanInterface wlanInterface in wlanClient.Interfaces)
    {
        Wlan.WlanBssEntry[] wlanBssEntries = wlanInterface.GetNetworkBssList();

        foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries)
        {
            int rss = wlanBssEntry.rssi;

            byte[] macAddr = wlanBssEntry.dot11Bssid;

            var macAddrLen = (uint)macAddr.Length;
           
            var str = new string[(int)macAddrLen];
           
            for (int i = 0; i < macAddrLen; i++)
            {
                if( i == macAddrLen - 1)
                    str[i] = macAddr[i].ToString("X2");
                else
                    str[i] = macAddr[i].ToString("X2") + ":";
            }
           
            string mac = string.Join("", str);

            MessageBox.Show(string.Format("AP MAC Address : {0}", mac));

            MessageBox.Show(string.Format("Found network with SSID : {0}.", System.Text.ASCIIEncoding.ASCII.GetString(wlanBssEntry.dot11Ssid.SSID)));

            MessageBox.Show(string.Format("Signal: {0}%.", wlanBssEntry.linkQuality));

            MessageBox.Show(string.Format("BSS Type: {0}.", wlanBssEntry.dot11BssType));

            MessageBox.Show(string.Format("MAC: {0}.", wlanBssEntry));

            MessageBox.Show(string.Format("RSSID:{0}", rss));
        }
    }
}

managedwifi-1.1.zip
0.02MB