예제 #1
0
        public static WLAN_BSS_ENTRY[] GetNetworkBssEntryList(SafeClientHandle clientHandle, Guid interfaceId, DOT11_SSID ssid, DOT11_BSS_TYPE bssType, bool isSecurityEnabled)
        {
            var queryData   = IntPtr.Zero;
            var wlanBssList = IntPtr.Zero;

            try
            {
                queryData = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
                Marshal.StructureToPtr(ssid, queryData, false);

                var result = WlanGetNetworkBssList(
                    clientHandle,
                    interfaceId,
                    queryData,
                    bssType,
                    isSecurityEnabled,
                    IntPtr.Zero,
                    out wlanBssList);

                // ERROR_NDIS_DOT11_POWER_STATE_INVALID will be returned if the interface is turned off.
                return(CheckResult(nameof(WlanGetNetworkBssList), result, false)
                                        ? new WLAN_BSS_LIST(wlanBssList).wlanBssEntries
                                        : new WLAN_BSS_ENTRY[0]);
            }
            finally
            {
                Marshal.FreeHGlobal(queryData);

                if (wlanBssList != IntPtr.Zero)
                {
                    WlanFreeMemory(wlanBssList);
                }
            }
        }
예제 #2
0
 internal NetworkIdentifier(DOT11_SSID ssid) : this(ssid.ToBytes(), ssid.ToString())
 {
 }
예제 #3
0
 public static string ConvertToString(this DOT11_SSID ssid)
 {
     return(ssid.ucSSID);
 }
예제 #4
0
        /// <summary>
        /// Retrieves a list of the basic service set (BSS) entries of the wireless network or networks from specified the SSID on a given wireless LAN interface.
        /// </summary>
        /// <param name="clientHandle"></param>
        /// <param name="interfaceId"></param>
        /// <param name="ssid"></param>
        /// <param name="bssType">dot11_BSS_type_infrastructure or dot11_BSS_type_independent</param>
        /// <returns></returns>
        public static IEnumerable <WLAN_BSS_ENTRY> GetNetworkBssEntryList(SafeClientHandle clientHandle, Guid interfaceId, DOT11_SSID ssid, DOT11_BSS_TYPE bssType)
        {
            IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));

            Marshal.StructureToPtr(ssid, ssidPtr, false);
            var wlanBssList = IntPtr.Zero;

            try
            {
                var result = WlanGetNetworkBssList(
                    clientHandle,
                    interfaceId,
                    ssidPtr,
                    bssType,
                    true,                 //must true
                    IntPtr.Zero,
                    out wlanBssList);

                // ERROR_NDIS_DOT11_POWER_STATE_INVALID will be returned if the interface is turned off.
                return(CheckResult(nameof(WlanGetNetworkBssList), result, false)
                                    ? new WLAN_BSS_LIST(wlanBssList).wlanBssEntries
                                    : new WLAN_BSS_ENTRY[0]);
            }
            finally
            {
                if (wlanBssList != IntPtr.Zero)
                {
                    WlanFreeMemory(wlanBssList);
                }
            }
        }