예제 #1
0
        /// <summary>
        /// Gets the current profile.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        internal static WifiProfile GetCurrentProfile(string[] input)
        {
            WifiProfile result = null;

            foreach (string item in input)
            {
                if (item.IndexOf("GUID") >= 0)
                {
                    result = new WifiProfile();
                    string guid = item.Substring(item.IndexOf(":") + 1).Trim();
                    result.InterfaceGuid = "{" + guid.ToUpper() + "}";
                }

                if (item.IndexOf("SSID") >= 0 && item.IndexOf("BSSID") == -1)
                {
                    string ssid = item.Substring(item.IndexOf(":") + 1).Trim();
                    result.SSID = ssid;
                }
            }

            WindowsNetworkCard card = WindowsNetworkCardManager.RefreshStatus(result.InterfaceGuid);

            result.InterfaceMAC         = card.MacAddress;
            result.InterfaceDescription = card.Description;
            result.InterfaceName        = card.Name;

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Gets the active wifi profile for card.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <returns></returns>
        public static WifiProfile GetActiveWifiProfileForCard(WindowsNetworkCard card)
        {
            WifiProfile wifi = ActiveWifiProfile;

            if (wifi != null && wifi.InterfaceMAC.Equals(card.MacAddress))
            {
                return(wifi);
            }

            return(null);
        }
예제 #3
0
        public void TestCurrentWifiProfile()
        {
            try
            {
                WifiProfile profile = WifiProfileManager.ActiveWifiProfile;

                if (profile != null)
                {
                    Debug.WriteLine(" Current wifi profile " + profile.SSID + " on " + profile.InterfaceName + " " + profile.InterfaceGuid);
                }
            }
            catch (ManagementException e)
            {
                Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the profiles.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns></returns>
        internal static List <WifiProfile> GetProfiles(string[] buffer)
        {
            List <WifiProfile>        ret        = new List <WifiProfile>();
            List <WindowsNetworkCard> cards      = WindowsNetworkCardManager.WindowsNetworkCardList;
            WindowsNetworkCard        currentNic = null;
            WifiProfile currentWifiProfile       = null;

            foreach (string item in buffer)
            {
                if (item.EndsWith(":"))
                {
                    currentNic = null;
                    // first row, get the current nics
                    foreach (WindowsNetworkCard nic in cards)
                    {
                        if (item.Contains(nic.Description + ":"))
                        {
                            currentNic = nic;
                            break;
                        }
                    }
                }
                else if (item.Contains(":") && currentNic != null)
                {
                    currentWifiProfile = new WifiProfile();
                    string ssid = item.Substring(item.IndexOf(":") + 1).Trim();
                    currentWifiProfile.SSID          = ssid;
                    currentWifiProfile.InterfaceGuid = currentNic.Id;

                    currentWifiProfile.InterfaceMAC         = currentNic.MacAddress;
                    currentWifiProfile.InterfaceDescription = currentNic.Description;
                    currentWifiProfile.InterfaceName        = currentNic.Name;

                    ret.Add(currentWifiProfile);
                }
            }

            return(ret);
        }