Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Lazarus - MacOS X - How to get available WiFi SSID's
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
August 21, 2016 3:03 AM
I wrote this small function to retrieve the available SSID's of WiFi access points in your area (the ones your computer can see).
Hope it's useful to someone. Note that this works on MacOS X only and that you need to add uses process to your code.
{ GetAvailableWiFiSSIDs
Scan WiFi network for available SSID's
Returns a string with SSID's separated by new lines
or "(no WiFi networks found)" when WiFi was disabled, unavailable or no networks were found }
function GetAvailableWiFiSSIDs:string;
var s : ansistring;
dataText:TStringList;
cutOffPosition:integer;
Counter:integer;
begin
s:='';
if RunCommand('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport',['-s'],s) and (s<>'') then
begin
dataText:=TStringList.Create;
dataText.Text:=s;
if dataText.Count>0 then
begin
cutOffPosition:=pos(' BSSID',dataText.Strings[0])-1; // BSSID is lined up with the end of SSID
for Counter:=0 to dataText.Count-1 do
dataText.Strings[Counter]:=Trim(Copy(dataText.Strings[Counter],0,cutOffPosition));
dataText.Delete(0); // first line is just a header
s:=dataText.Text;
dataText.Free;
end;
end;
if s='' then s:='(no WiFi networks found)';
GetAvailableWiFiSSIDs := s;
end;