예제 #1
0
        public void conectwifi()
        {
            if (FindWifi().Item1)

            {
                CustomMessageBox.Show("Trying to connect..");
                // for each access point from list
                foreach (AccessPoint ap in FindWifi().Item2.Where(i => i.Name == Name_wifi))
                {
                    if (ap.IsConnected)
                    {
                        objwifi.Disconnect();
                    }
                    AuthRequest authRequest = new AuthRequest(ap);
                    authRequest.Password = password;
                    ap.Name.startswith(Name_wifi);
                    if (ap.Connect(authRequest))
                    {
                        CustomMessageBox.Show("Connected", "Success");
                        status_conection = true;
                        startTimer();
                    }
                    else
                    {
                        CustomMessageBox.Show("Error de Contraseña", "Error");
                        status_conection = false;
                    }
                }
                ChangePriority();
            }
        }
예제 #2
0
        private static void Execute(string command)
        {
            switch (command)
            {
            case "l":
                List();
                break;

            case "d":
                _wifi.Disconnect();
                break;

            case "c":
                Connect();
                break;

            case "s":
                Console.WriteLine("\r\n-- CONNECTION STATUS --");
                Console.WriteLine(_wifi.ConnectionStatus == WifiStatus.Connected
                        ? "You are connected to a wifi"
                        : "You are not connected to a wifi");
                break;

            case "x":
                ProfileXml();
                break;

            case "r":
                DeleteProfile();
                break;

            case "i":
                ShowInfo();
                break;

            case "f":
                Finder();
                break;

            case "q":
                break;

            case "t":
                AutoFind();
                break;

            default:
                Console.WriteLine("\r\nIncorrect command.");
                break;
            }
        }
예제 #3
0
 private void отключитьсяToolStripMenuItem_Click(object sender, EventArgs e)
 {
     toolStripStatusLabel1.Text = "Ручное отключение от точки доступа: " + current_ap;
     Logger.WriteLine("Ручное отключение от точки доступа: " + current_ap);
     wifi.Disconnect();
     current_ap = "";
 }
예제 #4
0
        public void Connect(string ssid, string passphrase = null)
        {
            var conf = new WifiConfiguration
            {
                Ssid = $"\"{ssid}\""
            };

            // very important for unprotected networks otherwise connection doesn't go on
            if (passphrase == null)
            {
                conf.AllowedKeyManagement.Set((int)KeyManagementType.None);
            }
            else
            {
                conf.AllowedKeyManagement.Set((int)KeyManagementType.WpaPsk);
                conf.PreSharedKey = $"\"{passphrase}\"";
            }

            var netId = Wifi.AddNetwork(conf);

            currentNetwork = Wifi.ConnectionInfo.NetworkId;
            Wifi.Disconnect();
            var connected = Wifi.EnableNetwork(netId, true);

            if (connected)
            {
                Wifi.Reconnect();
            }
        }
예제 #5
0
파일: Form1.cs 프로젝트: yuanhuihai/wifiCon
 private void wifiDis_Click(object sender, EventArgs e)
 {
     if (wifi.ConnectionStatus == WifiStatus.Connected)
     {
         wifi.Disconnect();
     }
 }
예제 #6
0
 // Disconnect current connection
 private void btnDisconnect_Click(object sender, EventArgs e)
 {
     if (wifi.ConnectionStatus == WifiStatus.Connected)
     {
         wifi.Disconnect();
         lblConnStatus.Text      = "OFFLINE";
         lblConnStatus.ForeColor = Color.Red;
         MessageBox.Show("You have been disconnected.", "Disconnected From WiFi");
     }
     btnConnect.Visible    = true;
     btnDisconnect.Visible = false;
 }
예제 #7
0
        public static bool disconnect()
        {
            bool ret  = false;
            var  wifi = new Wifi();

            try
            {
                wifi.Disconnect();
                ret = true;
            }
            catch
            {
                ret = false;
            }
            return(ret);
        }
예제 #8
0
        /*
         * public void Connect(string name, string password)
         * {
         *  var client = new WlanClient();
         *  foreach (var wlanIface in client.Interfaces)
         *  {
         *      var wlanBssEntries = wlanIface.GetAvailableNetworkList(0);
         *      foreach (var network in wlanBssEntries)
         *      {
         *          var profileName = Encoding.ASCII.GetString(network.dot11Ssid.SSID);
         *          if (profileName == name)
         *          {
         *              var strTemplate = "";
         *              var authentication = "";
         *              switch ((int)network.dot11DefaultAuthAlgorithm)
         *              {
         *                  case 1: // Open
         *                      break;
         *                  case 3: // WEP
         *                      break;
         *                  case 4: // WPA_PSK
         *                      strTemplate = Properties.Resources.WPAPSK;
         *                      authentication = "WPAPSK";
         *                      var encryption = network.dot11DefaultCipherAlgorithm.ToString().Trim((char)0);
         *                      var profileXml = string.Format(strTemplate, profileName, authentication, encryption, password);
         *                      wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
         *                      wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
         *                      break;
         *
         *                  default:
         *                      break;
         *              }
         *          }
         *      }
         *  }
         * }
         */


        public bool Connect(string name, string password)
        {
            var wifi = new Wifi();

            if (wifi.ConnectionStatus == WifiStatus.Connected)
            {
                wifi.Disconnect();
            }
            var selectedAP = wifi.GetAccessPoints().First(p => p.Name == name.Trim((char)0));

            if (selectedAP != null)
            {
                var authRequest = new AuthRequest(selectedAP);
                if (authRequest.IsPasswordRequired)
                {
                    authRequest.Password = password;
                }
                return(selectedAP.Connect(authRequest));
            }
            return(false);
        }
예제 #9
0
        private static void Run()
        {
            var wifi = new Wifi();

            if (wifi.NoWifiAvailable)
            {
                Console.WriteLine("No WiFi available");
                return;
            }

            if (wifi.ConnectionStatus == WifiStatus.Disconnected)
            {
                Console.WriteLine("WiFi not connected");
                return;
            }

            var connectedNetwork = wifi.GetAccessPoints().FirstOrDefault(n => n.IsConnected);

            if (connectedNetwork == null)
            {
                Console.WriteLine("Not connected to any WiFi network");
                return;
            }

            if (CanReachInternet())
            {
                Console.WriteLine($"Internet access working");
                return;
            }

            Console.WriteLine($"No internet access detected. Disconnecting from {connectedNetwork.Name}");
            wifi.Disconnect();

            Console.WriteLine("Waiting 15 seconds");
            Thread.Sleep(15000);

            Console.WriteLine($"Reconnecting to {connectedNetwork.Name}");
            connectedNetwork.Connect(new AuthRequest(connectedNetwork));
        }
예제 #10
0
        //private List<WIFISSID> ssids=new List<WIFISSID>();
        //private wifiSo wifiso;
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual
        {
            config = properties as DisConnectSsiProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            try
            {
                Wifi objWifi = configGv.GetObject("ObjWifi") as Wifi;
                if (objWifi != null)
                {
                    if (objWifi.ConnectionStatus == WifiStatus.Connected)
                    {
                        objWifi.Disconnect();
                        log.Info("断开WIFI连接成功");
                    }
                    else
                    {
                        throw new BaseException(string.Format("未连接WIFI热点,无法断开连接1"));
                    }
                }
                else
                {
                    throw new BaseException(string.Format("未连接WIFI热点,objWifi为空,无法断开连接"));
                }
                //if (!hasSsid)
                //{
                //    throw new BaseException(string.Format("未扫描到SSID:{0}", ssid));

                //}
            }
            catch (Exception ex)
            {
                throw new Exception("断开热点出错," + ex.Message);
            }
        }
예제 #11
0
 public static void Disconnect()
 {
     wifi.Disconnect();
 }
 private void disConnect()
 {
     wifi.Disconnect();
 }
예제 #13
0
 /// <summary>
 /// Рассоединение
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Disconnect(object sender, EventArgs e)
 {
     wifi.Disconnect();
     showRichTextBox2.Text += "-> Ты отключен от Wi-Fi\n";
 }
예제 #14
0
        public void Disconnect()
        {
            var wifi = new Wifi();

            wifi.Disconnect();
        }
예제 #15
0
 public static void Stop()
 {
     wifi.Disconnect();
     run = false;
     fd.Abort();
 }
예제 #16
0
 /// <summary>
 /// Разъединить WIFI
 /// </summary>
 public void Disconnect()
 {
     _wifi.Disconnect();
 }
예제 #17
0
 private static void Disconnect()
 {
     wifi.Disconnect();
 }
예제 #18
0
파일: DLG_Wifi.cs 프로젝트: luckypal/Kiosk
 private void Disconnect()
 {
     wifi.Disconnect();
 }
예제 #19
0
 public void DisconnectNetwork()
 {
     Wifi.Disconnect();
     ScanWiFiList = Wifi.GetAccessPoints();
     ScanWiFiList.ForEach(e => e.DeleteProfile());
 }
예제 #20
0
 /// <summary>
 /// 연결된 AccessPoint에서 연결 해제하는 함수(WiFi 연결 해제)
 /// </summary>
 public void wifi_disconn()
 {
     Console.WriteLine("-->DisConnection");
     Wifi.Disconnect();
 }
예제 #21
0
 /// <summary>
 /// Disconnects the currently connected access point if there is any.
 /// </summary>
 public static void Disconnect()
 {
     Wifi?.Disconnect();
 }
예제 #22
0
 private void btn_disconnect_Click(object sender, EventArgs e)
 {
     wifi.Disconnect();
     Status();
 }
예제 #23
0
        private void button_disconnect_Click(object sender, EventArgs e)
        {
            _wifiConnectClient.Disconnect();

            _ui_update_connect_state(false);
        }