2

我想编写一个简单的实用程序来定期将我的 WiFi 路由器的 RSSI 记录到文本文件中。有人知道 Delphi 库或 API 包装器来读取无线路由器的 RSSI 值吗?

4

1 回答 1

4

您可以使用Native Wifi API获取活动网络 wifi 连接的 RSSI ,在调用WlanOpenHandleWlanEnumInterfaces函数之后,您必须执行WlanQueryInterface传递wlan_intf_opcode_current_connection枚举值和指向WLAN_CONNECTION_ATTRIBUTES结构的指针的方法,从这里您必须访问wlanAssociationAttributes元素并最终读取字段的值wlanSignalQuality

这是该字段的描述。

wlan信号质量

A percentage value that represents the signal quality of the network. 

WLAN_SIGNAL_QUALITY 是 ULONG 类型。该成员包含一个介于 0 和 100 之间的值。值 0 表示实际 RSSI 信号强度为 -100 dbm。值 100 表示实际 RSSI 信号强度为 -50 dbm。您可以使用线性插值计算介于 1 和 99 之间的 wlanSignalQuality 值的 RSSI 信号强度值。

试试这个示例代码

uses
  Windows,
  SysUtils,
  nduWlanAPI   in 'nduWlanAPI.pas',
  nduWlanTypes in 'nduWlanTypes.pas';

procedure Scan();
var
  hClient              : THandle;
  dwVersion            : DWORD;
  ResultInt            : DWORD;
  pInterface           : Pndu_WLAN_INTERFACE_INFO_LIST;
  i                    : Integer;
  pInterfaceGuid       : TGUID;
  pdwDataSize, RSSI    : DWORD;
  ppData               : pndu_WLAN_CONNECTION_ATTRIBUTES;
begin
  ResultInt:=WlanOpenHandle(1, nil, @dwVersion, @hClient);
 try
  if  ResultInt<> ERROR_SUCCESS then
  begin
     WriteLn('Error Open CLient'+IntToStr(ResultInt));
     Exit;
  end;

  ResultInt:=WlanEnumInterfaces(hClient, nil, @pInterface);
  if  ResultInt<> ERROR_SUCCESS then
  begin
     WriteLn('Error Enum Interfaces '+IntToStr(ResultInt));
     exit;
  end;

  for i := 0 to pInterface^.dwNumberOfItems - 1 do
  begin
    Writeln('Interface  ' + pInterface^.InterfaceInfo[i].strInterfaceDescription);
    WriteLn('GUID       ' + GUIDToString(pInterface^.InterfaceInfo[i].InterfaceGuid));
    pInterfaceGuid:= pInterface^.InterfaceInfo[pInterface^.dwIndex].InterfaceGuid;

    ppData:=nil;
    pdwDataSize:=0;
    ResultInt:=WlanQueryInterface(hClient, @pInterfaceGuid, wlan_intf_opcode_current_connection, nil, @pdwDataSize, @ppData,nil);
    try
      if (ResultInt=ERROR_SUCCESS) and (pdwDataSize=SizeOf(Tndu_WLAN_CONNECTION_ATTRIBUTES)) then
      begin
        Writeln(Format('Profile %s',[ppData^.strProfileName]));
        Writeln(Format('Mac Address %.2x:%.2x:%.2x:%.2x:%.2x:%.2x',[
        ppData^.wlanAssociationAttributes.dot11Bssid[0],
        ppData^.wlanAssociationAttributes.dot11Bssid[1],
        ppData^.wlanAssociationAttributes.dot11Bssid[2],
        ppData^.wlanAssociationAttributes.dot11Bssid[3],
        ppData^.wlanAssociationAttributes.dot11Bssid[4],
        ppData^.wlanAssociationAttributes.dot11Bssid[5]]));
        RSSI := (ppData^.wlanAssociationAttributes.wlanSignalQuality div 2) - 100;
        Writeln(Format('RSSI %d dbm',[RSSI]));
      end;
    finally
      if ppData<>nil then
       WlanFreeMemory(ppData);
    end;
  end;
 finally
  WlanCloseHandle(hClient, nil);
 end;
end;

begin
  try
    Scan();
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
  Readln;
end.

注意:不幸的是,AFAIK 不存在将 Native Wifi API 标头转换为 Delphi 的官方翻译,因此您可以同时使用这些.

于 2013-01-15T03:45:01.993 回答