예제 #1
0
        /// <summary>
        /// Changes the automatic connection and automatic switch elements of a wireless profile.
        /// </summary>
        /// <param name="enableAutoConnect">Whether automatic connection should be enabled</param>
        /// <param name="enableAutoSwitch">Whether automatic switch should be enabled</param>
        /// <returns>True if successfully changed. False if not.</returns>
        /// <remarks>A wireless profile made by group policy will be skipped.</remarks>
        public static bool ChangeProfile(bool enableAutoConnect, bool enableAutoSwitch)
        {
            var targetProfile = NativeWifi.EnumerateProfiles()
                                .FirstOrDefault(x => x.ProfileType != ProfileType.GroupPolicy);

            if (targetProfile == null)
            {
                return(false);
            }

            if ((targetProfile.Document.IsAutoConnectEnabled == enableAutoConnect) &&
                (targetProfile.Document.IsAutoSwitchEnabled == enableAutoSwitch))
            {
                return(false);
            }

            // Set IsAutoConnectEnabled first.
            targetProfile.Document.IsAutoConnectEnabled = enableAutoConnect;
            targetProfile.Document.IsAutoSwitchEnabled  = enableAutoSwitch;

            return(NativeWifi.SetProfile(
                       interfaceId: targetProfile.Interface.Id,
                       profileType: targetProfile.ProfileType,
                       profileXml: targetProfile.Document.Xml,
                       profileSecurity: null,          // No change
                       overwrite: true));
        }
예제 #2
0
        /// <summary>
        /// Deletes a specified wireless profile.
        /// </summary>
        /// <param name="profileName">Profile name to be deleted</param>
        /// <returns>True if successfully deleted. False if not.</returns>
        /// <remarks>Profile name is case-sensitive.</remarks>
        public static bool DeleteProfile(string profileName)
        {
            var targetProfile = NativeWifi.EnumerateProfiles()
                                .Where(x => profileName.Equals(x.Name, StringComparison.Ordinal))
                                .FirstOrDefault();

            if (targetProfile == null)
            {
                return(false);
            }

            return(NativeWifi.DeleteProfile(
                       interfaceId: targetProfile.Interface.Id,
                       profileName: profileName));
        }
        public async Task <IEnumerable <ProfileItem> > GetProfilesAsync(bool isLatest, TimeSpan timeout)
        {
            if (isLatest)
            {
                await NativeWifi.ScanNetworksAsync(timeout).ConfigureAwait(false);
            }

            var profilePacks = await Task.Run(() => NativeWifi.EnumerateProfiles()).ConfigureAwait(false);

            return(profilePacks.Select(x => new NativeWifiProfileItem(
                                           name: x.Name,
                                           interfaceId: x.Interface.Id,
                                           interfaceDescription: x.Interface.Description,
                                           profileType: x.ProfileType,
                                           document: x.Document,
                                           position: x.Position,
                                           signal: x.SignalQuality,
                                           isConnected: x.IsConnected)));
        }
예제 #4
0
        public async Task <IEnumerable <ProfileItem> > GetProfilesAsync(bool isLatest, TimeSpan timeout)
        {
            if (isLatest)
            {
                await NativeWifi.ScanNetworksAsync(timeout).ConfigureAwait(false);
            }

            var profilePacks = await Task.Run(() => NativeWifi.EnumerateProfiles()).ConfigureAwait(false);

            return(profilePacks.Select(x => new ProfileItem(
                                           name: x.Name,
                                           interfaceId: x.Interface.Id,
                                           interfaceName: null,
                                           interfaceDescription: x.Interface.Description,
                                           authentication: ConvertToAuthentication(x.Authentication),
                                           encryption: ConvertToEncryption(x.Encryption),
                                           position: x.Position,
                                           isAutomatic: x.IsAutomatic,
                                           signal: x.SignalQuality,
                                           isConnected: x.IsConnected)));
        }
예제 #5
0
        private static void ShowInformation()
        {
            Trace.WriteLine("===== Usable Interfaces =====");
            foreach (var interfaceInfo in NativeWifi.EnumerateInterfaces())
            {
                Trace.WriteLine($"Interface: {interfaceInfo.Description} ({interfaceInfo.Id})");
            }

            Trace.WriteLine("===== Usable Interface Connections =====");
            foreach (var interfaceInfo in NativeWifi.EnumerateInterfaceConnections())
            {
                Trace.WriteLine($"{{Interface: {interfaceInfo.Description} ({interfaceInfo.Id})");
                Trace.WriteLine($" Connection: {interfaceInfo.ConnectionMode}");
                Trace.WriteLine($" RadioOn: {interfaceInfo.IsRadioOn}");
                Trace.WriteLine($" Connected: {interfaceInfo.IsConnected}");
                Trace.WriteLine($" Profile: {interfaceInfo.ProfileName}}}");
            }

            Trace.WriteLine("===== Available Network SSIDs =====");
            foreach (var ssid in NativeWifi.EnumerateAvailableNetworkSsids())
            {
                Trace.WriteLine($"SSID: {ssid}");
            }

            Trace.WriteLine("===== Connected Network SSIDs =====");
            foreach (var ssid in NativeWifi.EnumerateConnectedNetworkSsids())
            {
                Trace.WriteLine($"SSID: {ssid}");
            }

            Trace.WriteLine("===== Available Networks =====");
            foreach (var network in NativeWifi.EnumerateAvailableNetworks())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BSS: {network.BssType}");
                Trace.WriteLine($" SignalQuality: {network.SignalQuality}");
                Trace.WriteLine($" Security: {network.IsSecurityEnabled}}}");
            }

            Trace.WriteLine("===== Available Network Groups =====");
            foreach (var network in NativeWifi.EnumerateAvailableNetworkGroups())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BssNetworks: {network.BssNetworks.Count}");
                Trace.WriteLine($" SignalQuality: {network.SignalQuality}");
                Trace.WriteLine($" LinkQuality: {network.LinkQuality}");
                Trace.WriteLine($" Band: {network.Band} GHz");
                Trace.WriteLine($" Channel: {network.Channel}}}");
            }

            Trace.WriteLine("===== BSS Networks =====");
            foreach (var network in NativeWifi.EnumerateBssNetworks())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BSS: {network.BssType}");
                Trace.WriteLine($" BSSID: {network.Bssid}");
                Trace.WriteLine($" SignalStrength: {network.SignalStrength}");
                Trace.WriteLine($" LinkQuality: {network.LinkQuality}");
                Trace.WriteLine($" Frequency: {network.Frequency} KHz");
                Trace.WriteLine($" Band: {network.Band} GHz");
                Trace.WriteLine($" Channel: {network.Channel}}}");
            }

            Trace.WriteLine("===== Network Profile Names =====");
            foreach (var name in NativeWifi.EnumerateProfileNames())
            {
                Trace.WriteLine($"Name: {name}");
            }

            Trace.WriteLine("===== Network Profiles =====");
            foreach (var profile in NativeWifi.EnumerateProfiles())
            {
                Trace.WriteLine($"{{Name: {profile.Name}");
                Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})");
                Trace.WriteLine($" SSID: {profile.Document.Ssid}");
                Trace.WriteLine($" BSS: {profile.Document.BssType}");
                Trace.WriteLine($" Authentication: {profile.Document.Authentication}");
                Trace.WriteLine($" Encryption: {profile.Document.Encryption}");
                Trace.WriteLine($" AutoConnect: {profile.Document.IsAutoConnectEnabled}");
                Trace.WriteLine($" AutoSwitch: {profile.Document.IsAutoSwitchEnabled}");
                Trace.WriteLine($" Position: {profile.Position}}}");
            }

            Trace.WriteLine("===== Network Profile Radios =====");
            foreach (var profile in NativeWifi.EnumerateProfileRadios())
            {
                Trace.WriteLine($"{{Name: {profile.Name}");
                Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})");
                Trace.WriteLine($" SSID: {profile.Document.Ssid}");
                Trace.WriteLine($" RadioOn: {profile.IsRadioOn}");
                Trace.WriteLine($" Connected: {profile.IsConnected}");
                Trace.WriteLine($" SignalQuality: {profile.SignalQuality}");
                Trace.WriteLine($" LinkQuality: {profile.LinkQuality}");
                Trace.WriteLine($" Band: {profile.Band} GHz");
                Trace.WriteLine($" Channel: {profile.Channel}}}");
            }
        }
예제 #6
0
        private static void ShowInformation()
        {
            Trace.WriteLine("[Usable Interfaces]");
            foreach (var interfaceInfo in NativeWifi.EnumerateInterfaces())
            {
                Trace.WriteLine($"Interface: {interfaceInfo.Description} ({interfaceInfo.Id})");
            }

            Trace.WriteLine("[Available Network SSIDs]");
            foreach (var ssid in NativeWifi.EnumerateAvailableNetworkSsids())
            {
                Trace.WriteLine($"SSID: {ssid}");
            }

            Trace.WriteLine("[Connected Network SSIDs]");
            foreach (var ssid in NativeWifi.EnumerateConnectedNetworkSsids())
            {
                Trace.WriteLine($"SSID: {ssid}");
            }

            Trace.WriteLine("[Available Networks]");
            foreach (var network in NativeWifi.EnumerateAvailableNetworks())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BSS: {network.BssType}");
                Trace.WriteLine($" Signal: {network.SignalQuality}");
                Trace.WriteLine($" Security: {network.IsSecurityEnabled}}}");
            }

            Trace.WriteLine("[BSS Networks]");
            foreach (var network in NativeWifi.EnumerateBssNetworks())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BSS: {network.BssType}");
                Trace.WriteLine($" BSSID: {network.Bssid}");
                Trace.WriteLine($" Signal: {network.SignalStrength}");
                Trace.WriteLine($" Link: {network.LinkQuality}");
                Trace.WriteLine($" Frequency: {network.Frequency}");
                Trace.WriteLine($" Channel: {network.Channel}}}");
            }

            Trace.WriteLine("[Network Profile Names]");
            foreach (var name in NativeWifi.EnumerateProfileNames())
            {
                Trace.WriteLine($"Name: {name}");
            }

            Trace.WriteLine("[Network Profiles]");
            foreach (var profile in NativeWifi.EnumerateProfiles())
            {
                Trace.WriteLine($"{{Name: {profile.Name}");
                Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})");
                Trace.WriteLine($" SSID: {profile.Ssid}");
                Trace.WriteLine($" BSS: {profile.BssType}");
                Trace.WriteLine($" Authentication: {profile.Authentication}");
                Trace.WriteLine($" Encryption: {profile.Encryption}");
                Trace.WriteLine($" Signal: {profile.SignalQuality}");
                Trace.WriteLine($" Position: {profile.Position}");
                Trace.WriteLine($" Automatic: {profile.IsAutomatic}");
                Trace.WriteLine($" Connected: {profile.IsConnected}}}");
            }
        }
예제 #7
0
        private static void ShowInformation()
        {
            Trace.WriteLine("[Usable Interfaces]");
            foreach (var interfaceInfo in NativeWifi.EnumerateInterfaces())
            {
                Trace.WriteLine($"Interface: {interfaceInfo.Description} ({interfaceInfo.Id})");
            }

            Trace.WriteLine("");
            Trace.WriteLine("[Available Network SSIDs]");
            foreach (var ssid in NativeWifi.EnumerateAvailableNetworkSsids())
            {
                Trace.WriteLine($"SSID: {ssid}");
            }

            Trace.WriteLine("");
            Trace.WriteLine("[Connected Network SSIDs]");
            foreach (var ssid in NativeWifi.EnumerateConnectedNetworkSsids())
            {
                Trace.WriteLine($"SSID: {ssid}");
            }

            Trace.WriteLine("");
            Trace.WriteLine("[Available Networks]");
            foreach (var network in NativeWifi.EnumerateAvailableNetworks())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BSS: {network.BssType}");
                Trace.WriteLine($" Signal: {network.SignalQuality}");
                Trace.WriteLine($" Security: {network.IsSecurityEnabled}");
                Trace.WriteLine($" Auth Algorithm: {network.AuthAlgorithm.ToString()}");
                Trace.WriteLine($" Has Profile: {network.IsHasProfile} {(network.IsHasProfile ? "(" + network.ProfileName + ")" : network.ProfileName)}");

                Trace.WriteLine($" Cipher Algorithm: {network.CipherAlgorithm.ToString()}}}");
                var bssNetworks = NativeWifi.EnumerateBssNetworks(network);
                if (bssNetworks != null)
                {
                    Trace.WriteLine("[Child BSS Networks]");
                    foreach (var bssNetwork in bssNetworks)
                    {
                        Trace.WriteLine($"{{BSSID: {bssNetwork.Bssid}");
                        Trace.WriteLine($" SSID: {bssNetwork.Ssid}");
                        Trace.WriteLine($" BSS: {bssNetwork.BssType}");
                        Trace.WriteLine($" Signal: {bssNetwork.SignalStrength}");
                        Trace.WriteLine($" Link: {bssNetwork.LinkQuality}");
                        Trace.WriteLine($" Frequency: {bssNetwork.Frequency}");
                        Trace.WriteLine($" Channel: {bssNetwork.Channel}}}");
                    }
                }
            }

            Trace.WriteLine("");
            Trace.WriteLine("[BSS Networks]");
            foreach (var network in NativeWifi.EnumerateBssNetworks())
            {
                Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})");
                Trace.WriteLine($" SSID: {network.Ssid}");
                Trace.WriteLine($" BSS: {network.BssType}");
                Trace.WriteLine($" BSSID: {network.Bssid}");
                Trace.WriteLine($" Signal: {network.SignalStrength}");
                Trace.WriteLine($" Link: {network.LinkQuality}");
                Trace.WriteLine($" Frequency: {network.Frequency}");
                Trace.WriteLine($" Channel: {network.Channel}}}");
            }

            Trace.WriteLine("");
            Trace.WriteLine("[Network Profile Names]");
            foreach (var name in NativeWifi.EnumerateProfileNames())
            {
                Trace.WriteLine($"Name: {name}");
            }

            Trace.WriteLine("");
            Trace.WriteLine("[Network Profiles]");
            foreach (var profile in NativeWifi.EnumerateProfiles())
            {
                Trace.WriteLine($"{{Name: {profile.Name}");
                Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})");
                Trace.WriteLine($" SSID: {profile.Document.Ssid}");
                Trace.WriteLine($" BSS: {profile.Document.BssType}");
                Trace.WriteLine($" Authentication: {profile.Document.Authentication}");
                Trace.WriteLine($" Encryption: {profile.Document.Encryption}");
                Trace.WriteLine($" AutoConnect: {profile.Document.IsAutoConnectEnabled}");
                Trace.WriteLine($" AutoSwitch: {profile.Document.IsAutoSwitchEnabled}");
                Trace.WriteLine($" Position: {profile.Position}");
                Trace.WriteLine($" RadioOn: {profile.IsRadioOn}");
                Trace.WriteLine($" Signal: {profile.SignalQuality}");
                Trace.WriteLine($" Connected: {profile.IsConnected}}}");
            }
        }