Exemplo n.º 1
0
        internal static IEnumerable <ProfilePack> EnumerateProfiles(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

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

                    var interfaceIsRadioOn = interfaceIsConnected || IsInterfaceRadioOn(container.Content, interfaceInfo.Id);

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

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

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

                    int position = 0;

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

                        var profileXml = Base.GetProfile(container.Content.Handle, interfaceInfo.Id, profileInfo.strProfileName, out uint profileTypeFlag);
                        if (string.IsNullOrWhiteSpace(profileXml))
                        {
                            continue;
                        }

                        if (!ProfileTypeConverter.TryConvert(profileTypeFlag, out ProfileType profileType))
                        {
                            continue;
                        }

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

                        yield return(new ProfilePack(
                                         name: profileInfo.strProfileName,
                                         interfaceInfo: interfaceInfo,
                                         profileType: profileType,
                                         profileXml: profileXml,
                                         position: position++,
                                         isRadioOn: interfaceIsRadioOn,
                                         signalQuality: signalQuality,
                                         isConnected: profileIsConnected));
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);
                    if (connection.isState != WLAN_INTERFACE_STATE.wlan_interface_state_connected)
                    {
                        continue;
                    }

                    var association = connection.wlanAssociationAttributes;

                    //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3}",
                    //	interfaceInfo.strInterfaceDescription,
                    //	association.dot11Ssid,
                    //	association.dot11Bssid,
                    //	association.wlanSignalQuality);

                    yield return(new NetworkIdentifier(association.dot11Ssid.ToBytes(), association.dot11Ssid.ToString()));
                }
            }
        }
Exemplo n.º 3
0
        internal static IEnumerable <InterfaceInfoEx> EnumerateInterfacesEx(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);

                    yield return(new InterfaceInfoEx(interfaceInfo, connection));
                }
            }
        }
Exemplo n.º 4
0
        internal static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle))
            {
                var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);
                if (connection.isState != WLAN_INTERFACE_STATE.wlan_interface_state_connected)
                {
                    continue;
                }

                var association = connection.wlanAssociationAttributes;

                yield return(new NetworkIdentifier(association.dot11Ssid));
            }
        }
Exemplo n.º 5
0
        internal static IEnumerable <InterfaceConnectionInfo> EnumerateInterfaceConnections(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle))
            {
                var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);

                var isConnected = (interfaceInfo.isState == WLAN_INTERFACE_STATE.wlan_interface_state_connected);
                var isRadioOn   = isConnected ||
                                  EnumerateInterfaceRadioSets(container.Content, interfaceInfo.InterfaceGuid).Any(x => x.On.GetValueOrDefault());

                yield return(new InterfaceConnectionInfo(
                                 interfaceInfo,
                                 connectionMode: ConnectionModeConverter.Convert(connection.wlanConnectionMode),
                                 isRadioOn: isRadioOn,
                                 isConnected: isConnected,
                                 profileName: connection.strProfileName));
            }
        }