-
Notifications
You must be signed in to change notification settings - Fork 0
/
jswlan.pas
132 lines (118 loc) · 3.78 KB
/
jswlan.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
unit jswlan;
interface
uses
Windows, SysUtils, nduWlanAPI, nduWlanTypes;
function wScan(): widestring;
implementation
uses
XSuperObject;
function DOT11_AUTH_ALGORITHM_To_String(Dummy: Tndu_DOT11_AUTH_ALGORITHM): AnsiString;
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): AnsiString;
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;
function wScan(): widestring;
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: AnsiString;
X: ISuperObject;
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;
Result := '[';
for i := 0 to pInterface^.dwNumberOfItems - 1 do
begin
X := SO;
X.S['name'] := pInterface^.InterfaceInfo[i].strInterfaceDescription;
X.S['guid'] := GUIDToString(pInterface^.InterfaceInfo[i].InterfaceGuid);
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
with X.A['networks'].O[j] {Auto Create} do
begin
S['ssid'] := PAnsiChar(@pAvailableNetworkList^.Network[j].dot11Ssid.ucSSID);
i['signal'] := pAvailableNetworkList^.Network[j].wlanSignalQuality;
s['auth'] := DOT11_AUTH_ALGORITHM_To_String(pAvailableNetworkList^.Network[j].dot11DefaultAuthAlgorithm);
s['cipher'] := DOT11_CIPHER_ALGORITHM_To_String(pAvailableNetworkList^.Network[j].dot11DefaultCipherAlgorithm);
end;
end;
Result := result + X.AsJSON + ',';
end;
if Length(Result)>5 then
delete(Result, length(Result), 1);
result := result + ']';
finally
WlanCloseHandle(hClient, nil);
end;
end;
end.