サーバレス練習帳

着眼大局着手小局

DelphiでWindowsPCが掴んでいるWIFIを検知

多分、次の2つを組み合わせればできる。

(1) netsh
stackoverflow.com

確かに、"netsh wlan show all"とか"wlan show interfaces"とかってコマンドラインに書けば、SSIDが出てきますものね。

(2) コマンドライン実行
mrxray.on.coocan.jp

そして、コマンドプロンプトはshellexecuteで実行します。

さぁ、やってみよう!
こんな感じでできました!

procedure TForm1.Button3Click(Sender: TObject);
var
  LFile     : String;
  LParams   : String;
  LSaveFile : String;
  LTextFile : TextFile;
  strLine     :string;
begin
  LSaveFile := ExtractFilePath(Application.ExeName) + 'wifi.txt';
  LFile := 'cmd.exe';

  LParams := '/c cd /d c:\&netsh wlan show interfaces > ' + AnsiQuotedStr(LSaveFile, '"');

  ShellExecute(Handle,
               'open',
               PChar(LFile),
               PChar(LParams),
               nil,
               SW_HIDE);

  AssignFile(LTextFile, 'wifi.txt');
  try
    Reset(LTextFile);
  except
    on e: Exception do
    begin
      ShowMessage('ERROR:' + e.Message);
      exit;
    end;
  end;
  while not Eof(LTextFile) do
  begin
    ReadLn(LTextFile, strLine); 
    if POS('SSID',strLine ) > 0 then
    begin
      edit1.Text:=Copy(strLine,POS(':',strLine)+2,Length(strLine)-POS(':',strLine)-1);
      break

    end;
  end;
  CloseFile(LTextFile);

end;