Пример #1
0
        private static List <WIFISSID> ListSSID()
        {
            List <WIFISSID> ssids = new List <WIFISSID>();

            WlanClient client = new WlanClient();

            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                // Lists all networks with WEP security
                Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                {
                    WIFISSID targetSSID = new WIFISSID();

                    targetSSID.wlanInterface     = wlanIface;
                    targetSSID.wlanSignalQuality = (int)network.wlanSignalQuality;
                    targetSSID.SSID = GetStringForSSID(network.dot11Ssid);
                    targetSSID.dot11DefaultAuthAlgorithm   = network.dot11DefaultAuthAlgorithm.ToString();
                    targetSSID.dot11DefaultCipherAlgorithm = network.dot11DefaultCipherAlgorithm.ToString();
                    ssids.Add(targetSSID);
                }
            }

            return(ssids);
        }
Пример #2
0
 public bool Proxy()
 {
     if (!IsProxy)
     {
         WIFISSID ssid = GetWIFISSID(proxyWifi);
         ConnectToSSID(ssid, proxyWifi_key);
         return(true);
     }
     return(false);
 }
Пример #3
0
        public bool UnProxy()
        {
            if (IsProxy)
            {
                WIFISSID ssid = GetWIFISSID(wifi);
                ConnectToSSID(ssid, wifi_key);
                return(true);
            }

            return(false);
        }
Пример #4
0
        private static void ConnectToSSID(WIFISSID ssid, string key)
        {
            try
            {
                String auth    = string.Empty;
                String cipher  = string.Empty;
                bool   isNoKey = false;
                String keytype = string.Empty;
                switch (ssid.dot11DefaultAuthAlgorithm)
                {
                case "IEEE80211_Open":
                    auth = "open"; break;

                case "RSNA":
                    auth = "WPA2PSK"; break;

                case "RSNA_PSK":
                    auth = "WPA2PSK"; break;

                case "WPA":
                    auth = "WPAPSK"; break;

                case "WPA_None":
                    auth = "WPAPSK"; break;

                case "WPA_PSK":
                    auth = "WPAPSK"; break;
                }
                switch (ssid.dot11DefaultCipherAlgorithm)
                {
                case "CCMP":
                    cipher  = "AES";
                    keytype = "passPhrase";
                    break;

                case "TKIP":
                    cipher  = "TKIP";
                    keytype = "passPhrase";
                    break;

                case "None":
                    cipher  = "none"; keytype = "";
                    isNoKey = true;
                    break;

                case "WWEP":
                    cipher  = "WEP";
                    keytype = "networkKey";
                    break;

                case "WEP40":
                    cipher  = "WEP";
                    keytype = "networkKey";
                    break;

                case "WEP104":
                    cipher  = "WEP";
                    keytype = "networkKey";
                    break;
                }

                if (isNoKey && !string.IsNullOrEmpty(key))
                {
                    Console.WriteLine(">>>>>>>>>>>>>>>>>无法连接网络!");
                    return;
                }
                if (!isNoKey && string.IsNullOrEmpty(key))
                {
                    Console.WriteLine("无法连接网络!");
                    return;
                }
                string profileName = ssid.SSID;
                string mac         = StringToHex(profileName);
                string profileXml  = string.Empty;
                if (!string.IsNullOrEmpty(key))
                {
                    profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>{2}</authentication><encryption>{3}</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>{4}</keyType><protected>false</protected><keyMaterial>{5}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>",
                                               profileName, mac, auth, cipher, keytype, key);
                }
                else
                {
                    profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>{2}</authentication><encryption>{3}</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>",
                                               profileName, mac, auth, cipher, keytype);
                }

                ssid.wlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);

                bool success = ssid.wlanInterface.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName, 15000);
                if (!success)
                {
                    Console.WriteLine("连接网络失败!");
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("连接网络失败!");
                return;
            }
        }