Detect the AP availables using the Native Wifi API library is really simple. to do this we need to use GetNetworkBssList function which is a wrapper for the function WlanGetNetworkBssList.
This source code uses the Managed Wifi API, The library uses the Native Wifi API, available since Windows Vista and Windows XP SP2 (in a limited fashion, and only after applying a hotfix provided in KB article 918997). Older versions of Windows are not supported.
Before running the code you need to download the library from this location. Build the project “ManagedWifi.csproj” and then add the reference to the source code listed below.
namespace DelphiPrismAPWifidetection;
//Author : Rodrigo Ruz. 2009-10-15
//Shine Your crazy Diamond.
interface
uses
NativeWifi,//You must add the reference to the library ManagedWifi.dll
System.Text;
type
ConsoleApp = class
private
class method GetStringForSSID(ssid : Wlan.Dot11Ssid ) : string;
class method FrequencyToChannel(freq:Longint) : Integer;
public
class method Main;
end;
implementation
class method ConsoleApp.FrequencyToChannel(freq:Longint) : Integer;
var
tmpval1,tmpval2 : Longint;
begin
tmpval1 := (freq mod 2412000) div 1000;
tmpval2 := tmpval1 div 5;
Result := tmpval2 + 1;
end;
class method ConsoleApp.GetStringForSSID(ssid : Wlan.Dot11Ssid ) : string;
begin
Result:= Encoding.ASCII.GetString( ssid.SSID, 0, Int32( ssid.SSIDLength) );
end;
class method ConsoleApp.Main;
begin
var client : WlanClient := new WlanClient();
for each wlanIface in client.Interfaces do
begin
Console.WriteLine( "┌---------------------------------------------------------------¬");
Console.WriteLine( "|{0,-15} {1,-45} |",'Interface', wlanIface.InterfaceDescription);
Console.WriteLine( "├---------------------------------------------------------------┤");
Console.WriteLine( "|{0,-15} {1,-45} |",'GUID', wlanIface.InterfaceGuid);
Console.WriteLine( "|{0,-15} {1,-45} |",'Name', wlanIface.InterfaceName);
Console.WriteLine( "|{0,-15} {1,-45} |",'State', wlanIface.InterfaceState.ToString());
Console.WriteLine( "└---------------------------------------------------------------┘");
var BssList : Array of Wlan.WlanBssEntry:= wlanIface.GetNetworkBssList();
for each BssItem in BssList do
begin
// for more info goto http://msdn.microsoft.com/en-us/library/ms706735%28VS.85%29.aspx
Console.WriteLine( "┌---------------------------------------------------------------¬");
Console.WriteLine( "|Network SSID {0,-40} |", GetStringForSSID(BssItem.dot11Ssid));
Console.WriteLine( "├---------------------------------------------------------------┤");
Console.WriteLine( "| Channel Freq. (Khz) {0,-40} |", BssItem.chCenterFrequency.ToString());
Console.WriteLine( "| Channel {0,-40} |", FrequencyToChannel(BssItem.chCenterFrequency).ToString());
Console.WriteLine( "| Rssi (dBm) {0,-40} |", BssItem.rssi.ToString());
Console.WriteLine( "| LinkQuality (%) {0,-40} |", BssItem.linkQuality.ToString());
Console.WriteLine( "| MAC {0,-40} |", BitConverter.ToString(BssItem.dot11Bssid));
Console.WriteLine( "| dot11PhyType {0,-40} |", BssItem.dot11BssPhyType.ToString());
Console.WriteLine( "| network type {0,-40} |", BssItem.dot11BssType.ToString());
Console.WriteLine( "└---------------------------------------------------------------┘");
end;
end;
Console.ReadLine();
end;
end.
Pingback: Is it Worth Living in the World of Wireless Connectivity? | ADSL 4 ME