Beispiel #1
0
        private void Tick(object sender, System.EventArgs e)
        {
            this.CurrentTime.Text = DateTime.Now.ToLocalTime().ToString();

            Wlan.WlanAvailableNetwork[] networks = WlanIface.GetAvailableNetworkList(0);
            foreach (Wlan.WlanAvailableNetwork network in networks)
            {
                string SSID = WlanHelper.GetStringForSSID(network.dot11Ssid);
                if (!SSID.Contains("?") && SSID.Length > 0)
                {
                    if (network.flags.HasFlag(Wlan.WlanAvailableNetworkFlags.Connected))
                    {
                        this.CurrentWifi.Text = SSID;
                    }
                    //如果有配置文件的SSID会重复出现。过滤掉
                    if (!WifiList.Items.Contains(SSID))
                    {
                        WifiList.Items.Add(SSID);
                        NetWorkList.Add(network);
                    }
                }
            }

            checkConnection();
        }
Beispiel #2
0
        private void checkConnection()
        {
            if (isDealing)
            {
                return;
            }

            if (!WlanHelper.IsConnectedInternet())
            {
                this.Ping.Text = "无网络";
                ReconnectWifi();
                return;
            }

            try
            {
                IPAddress[] addresslist = Dns.GetHostAddresses("www.baidu.com");
                if (addresslist[0].ToString().Length > 6)
                {
                    this.Ping.Text = "畅通";
                }
                else
                {
                    this.Ping.Text = "--";
                    ReconnectWifi();
                }
            }
            catch
            {
                this.Ping.Text = "无外网";
                ReconnectWifi();
            }
        }
Beispiel #3
0
 //重连wifi,分为3步:
 // ipconfig /release
 // ipconfig /renew
 // AutoConnect
 private void ReconnectWifi()
 {
     //如果没有外网,就断开重连
     isDealing = true;
     Console.WriteLine("断开网络");
     WlanHelper.DisConnect();
     Console.WriteLine("重新获取网络");
     WlanHelper.ReConnect();
     Console.WriteLine("自动连接");
     WlanHelper.SetAutoConnect(this.CurrentWifi.Text);
     isDealing = false;
 }