Delphi例程读取无线连接的RSSI?

标签 delphi logging wireless rssi

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

最佳答案

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

这是该字段的描述。

wlanSignalQuality

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

WLAN_SIGNAL_QUALITY is of type ULONG. This member contains a value between 0 and 100. A value of 0 implies an actual RSSI signal strength of -100 dbm. A value of 100 implies an actual RSSI signal strength of -50 dbm. You can calculate the RSSI signal strength value for wlanSignalQuality values between 1 and 99 using linear interpolation.

尝试这个示例代码

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 header 到 Delphi 的官方翻译,因此在此期间您可以使用 these .

关于Delphi例程读取无线连接的RSSI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14324706/

相关文章:

sql - SQL追加的Delphi 7中的表达式类型不匹配

delphi - 有没有 "Pos"函数来查找字节?

java - Log4J - SQL 数据截断

c++ - 使用 QT 如何在不读取整个文件的情况下删除文本文件中的第一行?

delphi - 如何阻止调试器进入delphi给定单元

delphi - 当 vcl 样式从 NC 区域删除时,TMainMenu 不显示

ruby - 禁用来自 webrick 的回显

iphone - 通过 iPhone 连接到 AT&T 无线网络的 Google 静态 map 无法正常工作

c - Linux内核无线设备驱动

networking - 适用于 Windows 7 的无线 Ad-Hoc 网状网络实现