Page 1 of 1
Forum

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!




Share:
Notifications
Clear all

Lazarus - MacOS X - How to get available WiFi SSID's


 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2018
Topic starter  

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;

ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: