コード例 #1
0
        /// <summary>
        /// Enumerates wireless LAN information on available networks.
        /// </summary>
        /// <returns>Wireless LAN information</returns>
        /// <remarks>If multiple profiles are associated with a same network, there will be multiple
        /// entries with the same SSID.</remarks>
        public static IEnumerable <AvailableNetworkPack> EnumerateAvailableNetworks()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => ConvertToInterfaceInfo(x)))
                {
                    var availableNetworkList = Base.GetAvailableNetworkList(client.Handle, interfaceInfo.Id);

                    foreach (var availableNetwork in availableNetworkList)
                    {
                        //Debug.WriteLine("Interface: {0}, SSID: {1}, Signal: {2}, Security: {3}",
                        //	interfaceInfo.Description,
                        //	availableNetwork.dot11Ssid,
                        //	availableNetwork.wlanSignalQuality,
                        //	availableNetwork.bSecurityEnabled);

                        yield return(new AvailableNetworkPack(
                                         interfaceInfo: interfaceInfo,
                                         ssid: new NetworkIdentifier(availableNetwork.dot11Ssid.ToBytes(), availableNetwork.dot11Ssid.ToString()),
                                         bssType: ConvertToBssType(availableNetwork.dot11BssType),
                                         signalQuality: (int)availableNetwork.wlanSignalQuality,
                                         isSecurityEnabled: availableNetwork.bSecurityEnabled,
                                         profileName: availableNetwork.strProfileName));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Enumerates wireless profile information in preference order.
        /// </summary>
        /// <returns>Wireless profile information</returns>
        public static IEnumerable <ProfilePack> EnumerateProfiles()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => ConvertToInterfaceInfo(x)))
                {
                    var interfaceIsConnected = (interfaceInfo.State == InterfaceState.Connected);

                    var availableNetworkList = Base.GetAvailableNetworkList(client.Handle, interfaceInfo.Id)
                                               .Where(x => !string.IsNullOrWhiteSpace(x.strProfileName))
                                               .ToArray();

                    var connection = Base.GetConnectionAttributes(client.Handle, interfaceInfo.Id);

                    var profileInfoList = Base.GetProfileInfoList(client.Handle, interfaceInfo.Id);

                    int position = 0;

                    foreach (var profileInfo in profileInfoList)
                    {
                        var availableNetwork = availableNetworkList.FirstOrDefault(x => x.strProfileName.Equals(profileInfo.strProfileName, StringComparison.Ordinal));
                        var signalQuality    = (int)availableNetwork.wlanSignalQuality;

                        var profileIsConnected = interfaceIsConnected && profileInfo.strProfileName.Equals(connection.strProfileName, StringComparison.Ordinal);

                        //Debug.WriteLine("Interface: {0}, Profile: {1}, Signal {2}, Position: {3}, Connected {4}",
                        //	interfaceInfo.Description,
                        //	profileInfo.strProfileName,
                        //	signalQuality,
                        //	position,
                        //	profileIsConnected);

                        var profile = GetProfile(
                            client.Handle,
                            interfaceInfo,
                            profileInfo.strProfileName,
                            signalQuality,
                            position++,
                            profileIsConnected);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Enumerates SSIDs of available wireless LANs.
        /// </summary>
        /// <returns>SSIDs</returns>
        public static IEnumerable <NetworkIdentifier> EnumerateAvailableNetworkSsids()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var availableNetworkList = Base.GetAvailableNetworkList(client.Handle, interfaceInfo.InterfaceGuid);

                    foreach (var availableNetwork in availableNetworkList)
                    {
                        //Debug.WriteLine("Interface: {0}, SSID: {1}, Signal: {2}",
                        //	interfaceInfo.strInterfaceDescription,
                        //	availableNetwork.dot11Ssid,
                        //	availableNetwork.wlanSignalQuality);

                        yield return(new NetworkIdentifier(availableNetwork.dot11Ssid.ToBytes(), availableNetwork.dot11Ssid.ToString()));
                    }
                }
            }
        }