public string[] GetProfiles()
        {
            if (interFace == null)
            {
                return new string[] { }
            }
            ;

            return(interFace.GetProfiles().Select(x => x.profileName).ToArray());
        }
        static void SelectCurrentWifi(Wlan.WlanAvailableNetwork network, WlanClient.WlanInterface wlanIface)
        {
            string name = GetStringForSSID(network.dot11Ssid);
            string xml  = "";

            foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
            {
                if (profileInfo.profileName == name) // this is typically the network's SSID
                {
                    xml = wlanIface.GetProfileXml(name);
                }
                else
                {
                    if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.None)
                    {
                        SelectWifiWithNoKey(name, ref wlanIface);
                    }
                    else
                    {
                        Console.WriteLine("没有WiFiProfile信息,请先创建登录信息");
                    }

                    //Console.ReadKey();
                }
            }
        }
Beispiel #3
0
        public static void AddProfiles(ListView lst, WlanClient.WlanInterface wlanIface)
        {
            lst.Groups.Clear();
            lst.Items.Clear();

            foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
            {
                if (string.IsNullOrEmpty(profileInfo.profileName))
                {
                    continue;
                }

                XmlSerializer deserializer = new XmlSerializer(typeof(WLANProfile));
                object        profile      = null;
                using (TextReader reader = new StringReader(wlanIface.GetProfileXmlUnencrypted(profileInfo.profileName)))
                {
                    profile = deserializer.Deserialize(reader);
                }

                if (profile == null)
                {
                    continue;
                }

                AddProfilesInformation(lst, (WLANProfile)profile);
            }
        }
        void UpdateProfiles()
        {
            profile_info = adapter.GetProfiles();
            profiles     = new string[profile_info.Length];

            for (int c = 0; c < profile_info.Length; c++)
            {
                profiles[c] = profile_info[c].profileName;
            }

            cb_select_profile.DataSource = profiles;
        }
Beispiel #5
0
 /// <summary>
 /// 是否有身份配置,有就直接连接了,不用输入什么密码了
 /// </summary>
 /// <param name="wlanIface"></param>
 /// <param name="profile"></param>
 /// <returns></returns>
 public static bool HasProfile(WlanClient.WlanInterface wlanIface, string profile)
 {
     Wlan.WlanProfileInfo[] p = wlanIface.GetProfiles();
     foreach (Wlan.WlanProfileInfo item in p)
     {
         if (item.profileName == profile)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #6
0
        public void Arcquire()
        {
            Profiles.Clear();

            WlanClient client = new WlanClient();

            // Lists all networks with WEP security
            Wlan.WlanAvailableNetwork[] networks = iFace.GetAvailableNetworkList(0);

            var x = new System.Xml.Serialization.XmlSerializer(typeof(WLANProfile));

            // Retrieves XML configurations of existing profiles.
            // This can assist you in constructing your own XML configuration
            foreach (Wlan.WlanProfileInfo profileInfo in iFace.GetProfiles())
            {
                string name = profileInfo.profileName; // this is typically the network's SSID

                string xml = iFace.GetProfileXml(name);

                using (TextReader reader = new StringReader(xml))
                {
                    var prov = x.Deserialize(reader) as WLANProfile;
                    Profiles.Add(new FiProfile(prov));
                }
            }

            foreach (var net in networks)
            {
                var ssid = net.dot11Ssid.ToStringBeauty();
                if (string.IsNullOrEmpty(ssid))
                {
                    continue;
                }
                var prof = Profiles.Where((p) => p.SSID == ssid).FirstOrDefault();
                if (prof != null)
                {
                    prof.SetAvailability(net);
                }
                else
                {
                    prof = new FiProfile(null);
                    prof.SetAvailability(net);
                    Profiles.Add(prof);
                }
            }

            Profiles.Sort(new FiProfileSorter());
        }
Beispiel #7
0
        /// <summary>
        /// Retrieves XML configurations of existing profiles.
        /// This can assist you in constructing your own XML configuration (that is, it will give you an example to follow).
        /// </summary>
        /// <param name="wlanIface"></param>
        /// <returns></returns>
        public static string GetWlanProfileXml(WlanClient.WlanInterface wlanIface)
        {
            StringBuilder profileXml = new StringBuilder();

            Wlan.WlanProfileInfo[] profiles = wlanIface.GetProfiles();
            foreach (Wlan.WlanProfileInfo profileInfo in profiles)
            {
                // This is typically the network's SSID.
                string name = profileInfo.profileName;
                string xml  = wlanIface.GetProfileXml(name);
                Debug.WriteLine(string.Format("Found Wifi profile for SSID {0}.", name));
                Debug.WriteLine(string.Format("Wifi profile xml {0}.", xml));
                profileXml.AppendLine(xml);
            }

            return(profileXml.ToString());
        }
        private Wlan.WlanAvailableNetwork?getChosenNetwork()
        {
            Debug.log("First connect");
            uint maxSignal = 0;

            Wlan.WlanAvailableNetwork?chosenNetwork = null;
            var profiles = m_Interface.GetProfiles();

            var networks = m_Interface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles);

            foreach (var network in networks)
            {
                if (network.networkConnectable && network.wlanSignalQuality > maxSignal /* && profileExists(network.profileName, profiles)*/)
                {
                    maxSignal     = network.wlanSignalQuality;
                    chosenNetwork = network;
                }
            }

            return(chosenNetwork);
        }
Beispiel #9
0
 void CheckProfiles()
 {
     mi_admin_profiles.Enabled = adapter.GetProfiles().Length > 0;
 }
Beispiel #10
0
 public Wlan.WlanProfileInfo[] GetProfiles()
 {
     return(_wlanInterface.GetProfiles());
 }
Beispiel #11
0
        private void Run()
        {
            this.LoadConfig();
            this.currentConfigCancelSource = new CancellationTokenSource();

            ServiceProxy coreService;

            try
            {
                coreService = new ServiceProxy()
                {
                    CanSendCallbacks = false
                };
                ServiceHost host = new ServiceHost(coreService);
                host.Open();
                coreService.SettingsUpdatedEvent += CoreService_SettingsUpdatedEvent;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }

            do
            {
                if (this.settings != null)
                {
                    coreService.Settings         = this.settings;
                    coreService.CanSendCallbacks = true;
                    Trace.TraceInformation(this.settings.ToString());
                    this.currentConfigCancelSource = new CancellationTokenSource();
                    WlanClient client = new WlanClient();
                    WlanClient.WlanInterface wlanIface = client.Interfaces.SingleOrDefault(p => p.InterfaceGuid.Equals(this.settings.WlanInterfaceId));
                    if (wlanIface == null)
                    {
                        throw new ArgumentException("The provided wlan interface id does not exist.");
                    }

                    byte[]        otpKey      = Base32.Base32Encoder.Decode(this.settings.SecretKeyBase32);
                    OtpSharp.Totp otpProvider = new OtpSharp.Totp(otpKey, this.settings.StepSeconds, totpSize: this.settings.TotpDigitCount);

                    WLANProfile defaultProfile = WLANProfile.Default(this.settings.ESSID);
                    if (wlanIface.GetProfiles().Any(p => p.profileName.Equals(this.settings.ESSID)))
                    {
                        wlanIface.DeleteProfile(this.settings.ESSID);
                    }

                    XmlSerializer xmlSer      = new XmlSerializer(typeof(WLANProfile));
                    string        textProfile = String.Empty;
                    using (StringWriter writer = new StringWriter())
                    {
                        xmlSer.Serialize(writer, defaultProfile);
                        textProfile = writer.ToString();
                    }

                    DateTime currentDate;
                    DateTime nextChange;
                    nextChange = currentDate = DateTime.UtcNow;

                    SHA1CryptoServiceProvider sha1Provider = new SHA1CryptoServiceProvider();
                    string pskhash = BitConverter.ToString(sha1Provider.ComputeHash(Encoding.ASCII.GetBytes(this.settings.PSHK))).Replace("-", "").ToLower();

                    do
                    {
                        try
                        {
                            double sleepSeconds = 0.1;
                            if (currentDate >= nextChange)
                            {
                                try
                                {
                                    //Generate key
                                    string otp      = otpProvider.ComputeTotp(currentDate);
                                    string totphash = BitConverter.ToString(sha1Provider.ComputeHash(Encoding.ASCII.GetBytes(otp))).Replace("-", "").ToLower();
                                    string newKey   = BitConverter.ToString(sha1Provider.ComputeHash(Encoding.ASCII.GetBytes(totphash + pskhash))).Replace("-", "").ToLower();
                                    Trace.TraceInformation(otp + " - " + newKey);
                                    //if (wlanIface.CurrentConnection.profileName.Equals(networkName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        string newProf = profileRegex.Replace(textProfile, $"<protected>false</protected><keyMaterial>{newKey}</keyMaterial>");
                                        wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, newProf, true);
                                        if (this.settings.AutoConnect)
                                        {
                                            //wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, defaultProfile.Name);
                                            wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, defaultProfile.Name);
                                        }
                                    }

                                    int desync = (int)DateTime.UtcNow.TimeOfDay.TotalSeconds % this.settings.StepSeconds;
                                    nextChange = DateTime.UtcNow.AddSeconds(this.settings.StepSeconds - desync);

                                    Task.Factory.StartNew(() => coreService.UpdateValues(newKey, nextChange));
                                    sleepSeconds = this.settings.StepSeconds - desync - 1;
                                    Trace.TraceInformation("Next change: " + nextChange.ToString("T"));
                                }
                                catch (Exception e)
                                {
                                    Trace.TraceError(e.ToString());
                                }
                            }

                            //Task.Delay(TimeSpan.FromSeconds(sleepSeconds), this.currentConfigCancelSource.Token).Wait();
                            this.currentConfigCancelSource.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(sleepSeconds));
                            currentDate = DateTime.UtcNow;
                        }
                        catch (AggregateException)
                        { }
                    } while (!this.currentConfigCancelSource.IsCancellationRequested);
                    sha1Provider.Dispose();
                }
                else
                {
                    coreService.CanSendCallbacks = false;
                    Trace.TraceInformation("Waiting for a valid settings");
                    //Task.Delay(TimeSpan.FromSeconds(10), this.currentConfigCancelSource.Token).Wait();
                    this.currentConfigCancelSource.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(60));
                }
            } while (!this.serviceCancelSource.IsCancellationRequested);
        }