예제 #1
0
        /// <summary>
        /// Enumerates wireless LAN information on BSS networks.
        /// </summary>
        /// <returns>Wireless LAN information</returns>
        public static IEnumerable <BssNetworkPack> EnumerateBssNetworks()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

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

                    foreach (var networkBssEntry in networkBssEntryList)
                    {
                        //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: ConvertToBssType(networkBssEntry.dot11BssType),
                                         bssid: new NetworkIdentifier(networkBssEntry.dot11Bssid.ToBytes(), networkBssEntry.dot11Bssid.ToString()),
                                         signalStrength: networkBssEntry.lRssi,
                                         linkQuality: (int)networkBssEntry.uLinkQuality,
                                         frequency: (int)networkBssEntry.ulChCenterFrequency,
                                         channel: DetectChannel(networkBssEntry.ulChCenterFrequency)));
                    }
                }
            }
        }
예제 #2
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));
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Enumerates SSIDs of connected wireless LANs.
        /// </summary>
        /// <returns>SSIDs</returns>
        public static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var connection = Base.GetConnectionAttributes(client.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()));
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Enumerates wireless interface information.
 /// </summary>
 /// <returns>Wireless interface information</returns>
 public static IEnumerable <InterfaceInfo> EnumerateInterfaces()
 {
     using (var client = new Base.WlanClient())
     {
         return(Base.GetInterfaceInfoList(client.Handle)
                .Select(x => ConvertToInterfaceInfo(x)));
     }
 }
예제 #5
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);
                        }
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Asynchronously requests wireless interfaces to scan (rescan) wireless LANs.
        /// </summary>
        /// <param name="timeout">Timeout duration</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Interface IDs that successfully scanned</returns>
        public static async Task <IEnumerable <Guid> > ScanNetworksAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);
                var interfaceIds      = interfaceInfoList.Select(x => x.InterfaceGuid).ToArray();

                var tcs     = new TaskCompletionSource <bool>();
                var handler = new ScanHandler(tcs, interfaceIds);

                Action <IntPtr, IntPtr> callback = (data, context) =>
                {
                    var notificationData = Marshal.PtrToStructure <WLAN_NOTIFICATION_DATA>(data);
                    if (notificationData.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM)
                    {
                        return;
                    }

                    Debug.WriteLine("Callback: {0}", (WLAN_NOTIFICATION_ACM)notificationData.NotificationCode);

                    switch (notificationData.NotificationCode)
                    {
                    case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_complete:
                        handler.SetSuccess(notificationData.InterfaceGuid);
                        break;

                    case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_fail:
                        handler.SetFailure(notificationData.InterfaceGuid);
                        break;
                    }
                };

                Base.RegisterNotification(client.Handle, WLAN_NOTIFICATION_SOURCE_ACM, callback);

                foreach (var interfaceId in interfaceIds)
                {
                    var result = Base.Scan(client.Handle, interfaceId);
                    if (!result)
                    {
                        handler.SetFailure(interfaceId);
                    }
                }

                var scanTask = tcs.Task;
                await Task.WhenAny(scanTask, Task.Delay(timeout, cancellationToken));

                return(handler.Results);
            }
        }
예제 #7
0
        /// <summary>
        /// Enumerates wireless profile names in preference order.
        /// </summary>
        /// <returns>Wireless profile names</returns>
        public static IEnumerable <string> EnumerateProfileNames()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

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

                    foreach (var profileInfo in profileInfoList)
                    {
                        //Debug.WriteLine("Interface: {0}, Profile: {1}",
                        //	interfaceInfo.strInterfaceDescription,
                        //	profileInfo.strProfileName);

                        yield return(profileInfo.strProfileName);
                    }
                }
            }
        }
예제 #8
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()));
                    }
                }
            }
        }