/// <summary> /// Retrieves the basic service sets (BSS) list of the specified network. /// </summary> /// <param name="ssid">Specifies the SSID of the network from which the BSS list is requested.</param> /// <param name="bssType">Indicates the BSS type of the network.</param> /// <param name="securityEnabled">Indicates whether security is enabled on the network.</param> public WlanBssEntry[] GetNetworkBssList(Dot11Ssid ssid, Dot11BssType bssType, bool securityEnabled) { IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid)); Marshal.StructureToPtr(ssid, ssidPtr, false); try { IntPtr bssListPtr; WlanInterop.ThrowIfError(WlanInterop.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, ssidPtr, bssType, securityEnabled, IntPtr.Zero, out bssListPtr)); try { return(ConvertBssListPtr(bssListPtr)); } finally { WlanInterop.WlanFreeMemory(bssListPtr); } } finally { Marshal.FreeHGlobal(ssidPtr); } }
/// <summary> /// Connects to the specified wireless network. /// </summary> /// <remarks> /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event. /// </remarks> public void Connect(WlanConnectionMode connectionMode, Dot11BssType bssType, Dot11Ssid ssid, WlanConnectionFlags flags) { WlanConnectionParameters connectionParams = new WlanConnectionParameters(); connectionParams.wlanConnectionMode = connectionMode; connectionParams.dot11SsidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid)); Marshal.StructureToPtr(ssid, connectionParams.dot11SsidPtr, false); connectionParams.dot11BssType = bssType; connectionParams.flags = flags; Connect(connectionParams); Marshal.DestroyStructure(connectionParams.dot11SsidPtr, ssid.GetType()); Marshal.FreeHGlobal(connectionParams.dot11SsidPtr); }
public static List <string> ReturnWifiSsids() { List <string> ssids = new List <string>(); //Making a WlanClient object WlanClient client = new WlanClient(); if (client.NoWifiAvailable == true) { WifiServices.AddWifiOperationEX(); throw new Exception("No WiFi Available"); } //Getting the current connection name foreach (WlanInterface wlanInterface in client.Interfaces) { Dot11Ssid ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid; ssids.Add(new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength))); } WifiServices.AddWifiOperation(ssids.FirstOrDefault()); return(ssids); }
static string GetStringForSSID(Dot11Ssid ssid) { return(Encoding.UTF8.GetString(ssid.SSID, 0, (int)ssid.SSIDLength)); }
public bool ConnectSync(Dot11Ssid ssid, bool discoverySecure, int timeout) { WlanConnectionMode mode = discoverySecure ? WlanConnectionMode.DiscoverySecure : WlanConnectionMode.DiscoveryUnsecure; return(ConnectSync(mode, null, null, Dot11BssType.Any, ssid, 0, timeout)); }
public void Connect(Dot11Ssid ssid, bool discoverySecure) { WlanConnectionMode mode = discoverySecure ? WlanConnectionMode.DiscoverySecure : WlanConnectionMode.DiscoveryUnsecure; Connect(mode, null, null, Dot11BssType.Any, ssid, 0); }