作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Delphi(Windows Xp 上)程序中,我想检查可用的 WiFi 网络。你知道该怎么做吗?最好的可能是使用 MS WlanScan API 函数,但我没有找到示例。有人可以帮助我吗?
最佳答案
您可以使用Native Wifi API ,自 Windows Vista 和 Windows XP 起可用。不支持旧版本的 Windows。
在此link您可以找到非常好的标题翻译。
我使用这些 header 编写了这段代码。在 Delphi 2007 和 Windows Vista 中进行了测试。
program DetectWifiUsingDelphi;
{$APPTYPE CONSOLE}
uses
Windows,
SysUtils,
//TypInfo,
nduWlanAPI in 'nduWlanAPI.pas',
nduWlanTypes in 'nduWlanTypes.pas';
function DOT11_AUTH_ALGORITHM_To_String( Dummy :Tndu_DOT11_AUTH_ALGORITHM):String;
begin
Result:='';
case Dummy of
DOT11_AUTH_ALGO_80211_OPEN : Result:= '80211_OPEN';
DOT11_AUTH_ALGO_80211_SHARED_KEY : Result:= '80211_SHARED_KEY';
DOT11_AUTH_ALGO_WPA : Result:= 'WPA';
DOT11_AUTH_ALGO_WPA_PSK : Result:= 'WPA_PSK';
DOT11_AUTH_ALGO_WPA_NONE : Result:= 'WPA_NONE';
DOT11_AUTH_ALGO_RSNA : Result:= 'RSNA';
DOT11_AUTH_ALGO_RSNA_PSK : Result:= 'RSNA_PSK';
DOT11_AUTH_ALGO_IHV_START : Result:= 'IHV_START';
DOT11_AUTH_ALGO_IHV_END : Result:= 'IHV_END';
end;
End;
function DOT11_CIPHER_ALGORITHM_To_String( Dummy :Tndu_DOT11_CIPHER_ALGORITHM):String;
Begin
Result:='';
case Dummy of
DOT11_CIPHER_ALGO_NONE : Result:= 'NONE';
DOT11_CIPHER_ALGO_WEP40 : Result:= 'WEP40';
DOT11_CIPHER_ALGO_TKIP : Result:= 'TKIP';
DOT11_CIPHER_ALGO_CCMP : Result:= 'CCMP';
DOT11_CIPHER_ALGO_WEP104 : Result:= 'WEP104';
DOT11_CIPHER_ALGO_WPA_USE_GROUP : Result:= 'WPA_USE_GROUP OR RSN_USE_GROUP';
//DOT11_CIPHER_ALGO_RSN_USE_GROUP : Result:= 'RSN_USE_GROUP';
DOT11_CIPHER_ALGO_WEP : Result:= 'WEP';
DOT11_CIPHER_ALGO_IHV_START : Result:= 'IHV_START';
DOT11_CIPHER_ALGO_IHV_END : Result:= 'IHV_END';
end;
End;
procedure Scan();
const
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES =$00000001;
var
hClient : THandle;
dwVersion : DWORD;
ResultInt : DWORD;
pInterface : Pndu_WLAN_INTERFACE_INFO_LIST;
i : Integer;
j : Integer;
pAvailableNetworkList: Pndu_WLAN_AVAILABLE_NETWORK_LIST;
pInterfaceGuid : PGUID;
SDummy : string;
begin
ResultInt:=WlanOpenHandle(1, nil, @dwVersion, @hClient);
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));
Writeln('');
pInterfaceGuid:= @pInterface^.InterfaceInfo[pInterface^.dwIndex].InterfaceGuid;
ResultInt:=WlanGetAvailableNetworkList(hClient,pInterfaceGuid,WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES,nil,pAvailableNetworkList);
if ResultInt<> ERROR_SUCCESS then
begin
WriteLn('Error WlanGetAvailableNetworkList '+IntToStr(ResultInt));
Exit;
end;
for j := 0 to pAvailableNetworkList^.dwNumberOfItems - 1 do
Begin
WriteLn(Format('Profile %s',[WideCharToString(pAvailableNetworkList^.Network[j].strProfileName)]));
SDummy:=PChar(@pAvailableNetworkList^.Network[j].dot11Ssid.ucSSID);
WriteLn(Format('NetworkName %s',[SDummy]));
WriteLn(Format('Signal Quality %d ',[pAvailableNetworkList^.Network[j].wlanSignalQuality])+'%');
//SDummy := GetEnumName(TypeInfo(Tndu_DOT11_AUTH_ALGORITHM),integer(pAvailableNetworkList^.Network[j].dot11DefaultAuthAlgorithm)) ;
SDummy:=DOT11_AUTH_ALGORITHM_To_String(pAvailableNetworkList^.Network[j].dot11DefaultAuthAlgorithm);
WriteLn(Format('Auth Algorithm %s ',[SDummy]));
SDummy:=DOT11_CIPHER_ALGORITHM_To_String(pAvailableNetworkList^.Network[j].dot11DefaultCipherAlgorithm);
WriteLn(Format('Auth Algorithm %s ',[SDummy]));
Writeln('');
End;
end;
WlanCloseHandle(hClient, nil);
end;
begin
try
Scan();
Readln;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.
alt text http://i33.tinypic.com/2z83ubt.jpg
再见。
关于delphi - 我想通过 Delphi 来使用 Wifi。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1527418/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!