internal static IEnumerable <InterfaceInfo> EnumerateInterfaces(Base.WlanClient client) { using var container = new DisposableContainer <Base.WlanClient>(client); return(Base.GetInterfaceInfoList(container.Content.Handle) .Select(x => new InterfaceInfo(x))); }
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)); } } } }
internal static IEnumerable <AvailableNetworkPack> EnumerateAvailableNetworks(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 availableNetworkList = Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.Id); foreach (var availableNetwork in availableNetworkList) { if (!BssTypeConverter.TryConvert(availableNetwork.dot11BssType, out BssType bssType)) { continue; } //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: bssType, signalQuality: (int)availableNetwork.wlanSignalQuality, isSecurityEnabled: availableNetwork.bSecurityEnabled, profileName: availableNetwork.strProfileName)); } } } }
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())); } } }
internal static IEnumerable <string> EnumerateProfileNames(Base.WlanClient client) { using var container = new DisposableContainer <Base.WlanClient>(client); foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle)) { foreach (var profileInfo in Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.InterfaceGuid)) { yield return(profileInfo.strProfileName); } } }
internal static IEnumerable <NetworkIdentifier> EnumerateAvailableNetworkSsids(Base.WlanClient client) { using var container = new DisposableContainer <Base.WlanClient>(client); foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle)) { foreach (var availableNetwork in Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.InterfaceGuid)) { yield return(new NetworkIdentifier(availableNetwork.dot11Ssid)); } } }
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)); } } }
internal static IEnumerable <BssNetworkPack> EnumerateBssNetworks(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(container.Content.Handle, x))) { var networkList = EnumerateAvailableNetworks(client); var networkBssEntryList = Base.GetNetworkBssEntryList(container.Content.Handle, interfaceInfo.Id); foreach (var networkBssEntry in networkBssEntryList) { if (!BssTypeConverter.TryConvert(networkBssEntry.dot11BssType, out BssType bssType)) { continue; } //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3} Link: {4}, Frequency: {5}", // interfaceInfo.Description, // networkBssEntry.dot11Ssid, // networkBssEntry.dot11Bssid, // networkBssEntry.lRssi, // networkBssEntry.uLinkQuality, // networkBssEntry.ulChCenterFrequency); var network = networkList.Where(o => o.Ssid.ToString() == new NetworkIdentifier(networkBssEntry.dot11Ssid.ToBytes(), networkBssEntry.dot11Ssid.ToString(), networkBssEntry.dot11Ssid.uSSIDLength).ToString()); //this program work get available network first and get bssnetwork list. //so if can not found network. just skip the bss network. //it just happen if you don't have a luck. if (!network.Any()) { continue; } yield return(new BssNetworkPack( interfaceInfo: interfaceInfo, network: network.First(), ssid: new NetworkIdentifier(networkBssEntry.dot11Ssid.ToBytes(), networkBssEntry.dot11Ssid.ToString(), networkBssEntry.dot11Ssid.uSSIDLength), bssType: bssType, bssid: new NetworkIdentifier(networkBssEntry.dot11Bssid.ToBytes(), networkBssEntry.dot11Bssid.ToString(), networkBssEntry.dot11Ssid.uSSIDLength), signalStrength: networkBssEntry.lRssi, linkQuality: (int)networkBssEntry.uLinkQuality, frequency: (int)networkBssEntry.ulChCenterFrequency, channel: DetectChannel(networkBssEntry.ulChCenterFrequency))); } } } }
internal static async Task <IEnumerable <Guid> > ScanNetworksAsync(Base.WlanNotificationClient client, TimeSpan timeout, CancellationToken cancellationToken) { if (timeout <= TimeSpan.Zero) { throw new ArgumentException(nameof(timeout)); } using (var container = new DisposableContainer <Base.WlanNotificationClient>(client)) { var interfaceIds = Base.GetInterfaceInfoList(container.Content.Handle) .Select(x => x.InterfaceGuid) .ToArray(); var tcs = new TaskCompletionSource <bool>(); var counter = new ScanCounter(() => Task.Run(() => tcs.TrySetResult(true)), interfaceIds); container.Content.NotificationReceived += (sender, data) => { switch ((WLAN_NOTIFICATION_ACM)data.NotificationCode) { case WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_complete: counter.SetSuccess(data.InterfaceGuid); break; case WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_fail: counter.SetFailure(data.InterfaceGuid); break; } }; foreach (var interfaceId in interfaceIds) { var result = Base.Scan(container.Content.Handle, interfaceId); if (!result) { counter.SetFailure(interfaceId); } } using (cancellationToken.Register(() => tcs.TrySetCanceled())) { var scanTask = tcs.Task; await Task.WhenAny(scanTask, Task.Delay(timeout, cancellationToken)); return(counter.Results); } } }
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)); } }
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)); } }
internal static IEnumerable <string> EnumerateProfileNames(Base.WlanClient client) { using (var container = new DisposableContainer <Base.WlanClient>(client)) { var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle); foreach (var interfaceInfo in interfaceInfoList) { var profileInfoList = Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.InterfaceGuid); foreach (var profileInfo in profileInfoList) { //Debug.WriteLine("Interface: {0}, Profile: {1}", // interfaceInfo.strInterfaceDescription, // profileInfo.strProfileName); yield return(profileInfo.strProfileName); } } } }
internal static IEnumerable <NetworkIdentifier> EnumerateAvailableNetworkSsids(Base.WlanClient client) { using (var container = new DisposableContainer <Base.WlanClient>(client)) { var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle); foreach (var interfaceInfo in interfaceInfoList) { var availableNetworkList = Base.GetAvailableNetworkList(container.Content.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())); } } } }
internal static IEnumerable <BssNetworkPack> EnumerateBssNetworks(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 networkBssEntryList = Base.GetNetworkBssEntryList(container.Content.Handle, interfaceInfo.Id); foreach (var networkBssEntry in networkBssEntryList) { if (!BssTypeConverter.TryConvert(networkBssEntry.dot11BssType, out BssType bssType)) { continue; } //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3} Link: {4}, Frequency: {5}", // interfaceInfo.Description, // networkBssEntry.dot11Ssid, // networkBssEntry.dot11Bssid, // networkBssEntry.lRssi, // networkBssEntry.uLinkQuality, // networkBssEntry.ulChCenterFrequency); yield return(new BssNetworkPack( interfaceInfo: interfaceInfo, ssid: new NetworkIdentifier(networkBssEntry.dot11Ssid.ToBytes(), networkBssEntry.dot11Ssid.ToString()), bssType: bssType, bssid: new NetworkIdentifier(networkBssEntry.dot11Bssid.ToBytes(), networkBssEntry.dot11Bssid.ToString()), signalStrength: networkBssEntry.lRssi, linkQuality: (int)networkBssEntry.uLinkQuality, frequency: (int)networkBssEntry.ulChCenterFrequency, channel: DetectChannel(networkBssEntry.ulChCenterFrequency))); } } } }