The next 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 to compile 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 DelphiPrismWifidetection; //Author : Rodrigo Ruz. 2009-09-29 //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 GetStringFornumberOfBssids (numberOfBssids : Int32 ) : string; public class method Main; end; implementation class method ConsoleApp.GetStringForSSID(ssid : Wlan.Dot11Ssid ) : string; begin Result:= Encoding.ASCII.GetString( ssid.SSID, 0, Int32( ssid.SSIDLength) ); end; class method ConsoleApp.GetStringFornumberOfBssids (numberOfBssids : Int32 ) : string; begin case numberOfBssids of 1: Result:='infrastructure'; 2: Result:='independent'; 3: Result:='any'; else Result:='Unknow'; end; // case end; class method ConsoleApp.Main; begin var client : WlanClient := new WlanClient(); for each wlanIface in client.Interfaces do begin var networks : Array of Wlan.WlanAvailableNetwork := wlanIface.GetAvailableNetworkList(NativeWifi.Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles); for each network in networks do begin // for more info goto http://msdn.microsoft.com/en-us/library/ms707403%28VS.85%29.aspx Console.WriteLine( "┌---------------------------------------------------------------¬"); Console.WriteLine( "|Network Detected {0,-40} |", GetStringForSSID(network.dot11Ssid)); Console.WriteLine( "├---------------------------------------------------------------┤"); Console.WriteLine( "| CipherAlgorithm {0,-40} |", network.dot11DefaultCipherAlgorithm.ToString()); Console.WriteLine( "| DefaultAuthAlgorithm {0,-40} |", network.dot11DefaultAuthAlgorithm.ToString()); Console.WriteLine( "| dot11Ssid {0,-40} |", network.dot11Ssid.ToString()); Console.WriteLine( "| networkConnectable {0,-40} |", network.networkConnectable.ToString()); if not network.networkConnectable then Console.WriteLine( "| NotConnectableReason {0,-40} |", network.wlanNotConnectableReason.ToString()); Console.WriteLine( "| morePhyTypes {0,-40} |", network.morePhyTypes.ToString()); Console.WriteLine( "| (BSS) network type {0,-40} |", GetStringFornumberOfBssids(network.numberOfBssids)); Console.WriteLine( "| profileName {0,-40} |", network.profileName.ToString()); Console.WriteLine( "| securityEnabled {0,-40} |", network.securityEnabled.ToString()); Console.WriteLine( "| wlanSignalQuality {0,-40} |", network.wlanSignalQuality.ToString()); Console.WriteLine( "└---------------------------------------------------------------┘"); end; end; Console.ReadLine(); end; end.
and the result is
Update
Download the full source code from here
Bye.
March 2, 2010 at 3:16 pm
I followed the guideline you gave but it dint work.. what could i have done wrong?
March 2, 2010 at 3:17 pm
Please could you send me your already made project via email? pls
March 2, 2010 at 11:01 pm
Danis, check the post update for download the full sourcecode.
March 3, 2010 at 7:55 am
I downloaded the source code but i encountered an error “Cannot open because of its project type(.oxygene) is not supported is this version of Visual Studio”. Please what version of visual studio did you use? or which software did you use if its not visual studio.
March 3, 2010 at 8:01 am
Danis, the project was compiled using Visual Studio 2008 (Version 9.0.30729.1 SP) and Delphi Prism 3.0.21.661
March 3, 2010 at 8:04 am
Okay but how do i use is will it run on vista?
March 3, 2010 at 12:52 pm
Yes , this code was tested in Windows Vista and Windows 7.
July 11, 2011 at 11:38 am
Rodrigo, first at all, thanks for posting the wifi code. Can you please update the download link? It seems to be that it is not longer available. Thanks!
July 11, 2011 at 7:20 pm
The link was updated.
September 2, 2013 at 2:15 pm
there was a similar version you made that worked in windows xp. i forget the exact link. but after a reinstall of xp home, and reruning this app, (no change in app) i am no longer able to see wife networks. did i install something inititially when i was compiling your other project that i need to reinstall ?
September 2, 2013 at 2:22 pm
i found the link. this is the project that i compiled under delphi 6. the app does not work on my xp home desk pc, but does work on my laptops.
https://theroadtodelphi.wordpress.com/2009/10/07/detecting-wifi-networks-using-delphi/
September 2, 2013 at 10:45 pm
Try this Native Wifi API Support on Windows XP
September 3, 2013 at 12:08 am
i miss being able to use that app. i made changes to it to run in window instead of dos console. looks better. but i can only use it on laptops and other pc’s. i removed something when i reinstalled windows xp home, but i would not know what it is. anyway. i’m unable to pass the Genuine Windows test, so it won’t let me download the “WindowsXP-KB918997-v6-x86-ENU.exe” file. if that is the file i need (and to install) to get this project working, is there another place i can download it from ?