基本信息
源码名称:C# 获取无线wifi列表信息
源码大小:0.26M
文件格式:.zip
开发语言:C#
更新时间:2017-03-13
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NativeWifi;
using System.Runtime.InteropServices;

namespace wlanManage
{
    public partial class Form1 : Form
    {
        [DllImport("wininet.dll")]
        public static extern bool InternetGetConnectedState(out long lpdwFlags, long dwReserved);

        public Form1()
        {
            InitializeComponent();
       //     Control.CheckForIllegalCrossThreadCalls = false;
        }

        static string GetStringForSSID(Wlan.Dot11Ssid ssid)
        {
            return Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
        }

        System.Windows.Forms.Timer timerTmp = new System.Windows.Forms.Timer();
        private void Form1_Load(object sender, EventArgs e)
        {
            timerTmp.Interval = 1000;
            timerTmp.Tick  = new EventHandler(timerTmp_Tick);
            timerTmp.Enabled = true;
        }

        Wlan.WlanAvailableNetwork[] wlanAvailableNetworks;
        private void refresh()
        {
            listView1.Items.Clear();
            WlanClient wlanClientTmp = new WlanClient();
            if (wlanClientTmp.Interfaces.Length != 0)
            {
                WlanClient.WlanInterface wlanInterfaceTmp = wlanClientTmp.Interfaces[0];
                Wlan.WlanAvailableNetwork[] wlanAvailableNetworksTmp
                    = wlanInterfaceTmp.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles);
                wlanAvailableNetworks = wlanAvailableNetworksTmp;
                int i = 1;
                foreach (Wlan.WlanAvailableNetwork wlanAvailableNetworkTmp in wlanAvailableNetworksTmp)
                {
                    ListViewItem lviTmp = new ListViewItem(
                        new string[]{   
                        (i  ).ToString(),
                        GetStringForSSID(wlanAvailableNetworkTmp.dot11Ssid),
                        wlanAvailableNetworkTmp.wlanSignalQuality.ToString()   "%",
                        wlanAvailableNetworkTmp.networkConnectable.ToString(),
                        wlanAvailableNetworkTmp.securityEnabled.ToString(),
                        Convert.ToInt64(wlanAvailableNetworkTmp.flags).ToString()
                        }
                    );
                    listView1.Items.Add(lviTmp);
                }
            }
        }

        private void timerTmp_Tick(object sender, EventArgs e)
        {
            try
            {
                timerTmp.Interval = 60000;
                refresh();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        private void button刷新列表_Click(object sender, EventArgs e)
        {
            try
            {
                refresh();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        private void wlanInterfaceTmp_WlanConnectionNotification(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
        {
            if (connNotifyData.profileName != "")
            {
                toolStripStatusLabel1.Text = "已连接至:"   connNotifyData.profileName;
            }
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                WlanClient wlanClientTmp = new WlanClient();

                if (wlanClientTmp.Interfaces.Length != 0)
                {
                    WlanClient.WlanInterface wlanInterfaceTmp = wlanClientTmp.Interfaces[0];                    
                    wlanInterfaceTmp.WlanConnectionNotification  = new WlanClient.WlanInterface.WlanConnectionNotificationEventHandler(wlanInterfaceTmp_WlanConnectionNotification);

                    int index = listView1.Items.IndexOf(listView1.SelectedItems[0]);
                    wlanInterfaceTmp.Connect(Wlan.WlanConnectionMode.Profile, wlanAvailableNetworks[index].dot11BssType, wlanAvailableNetworks[index].profileName);

                    toolStripStatusLabel1.Text = "正在连接网络:"   wlanAvailableNetworks[index].profileName;
                }
            }
            catch (Exception exp)
            {
                 MessageBox.Show(exp.Message);
            }
        }
    }
}