| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
local tonumber = tonumber |
| 22 |
local math = { ceil = math.ceil } |
| 23 |
local setmetatable = setmetatable |
| 24 |
local helpers = require("vicious.helpers") |
| 25 |
local io = { |
| 26 |
open = io.open, |
| 27 |
popen = io.popen |
| 28 |
} |
| 29 |
local string = { |
| 30 |
find = string.find, |
| 31 |
match = string.match |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
local wpa_all = {} |
| 38 |
|
| 39 |
local info = { |
| 40 |
["{ssid}"] = "N/A", |
| 41 |
["{bssid}"] = "N/A", |
| 42 |
["{ip}"] = "N/A", |
| 43 |
["{qual}"] = "N/A", |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
local function worker(format, warg) |
| 48 |
if not warg then return info end |
| 49 |
|
| 50 |
local wpa_cmd = "wpa_cli -i'" .. warg .. "' status 2>&1" |
| 51 |
local f = io.popen(wpa_cmd) |
| 52 |
local output = f:read("*all") |
| 53 |
f:close() |
| 54 |
|
| 55 |
if not output then return info end |
| 56 |
|
| 57 |
state = string.match(output, 'wpa_state=([%a]+)') or 'N/A' |
| 58 |
info["{bssid}"] = string.match(output, 'bssid=([%d%a:]+)') or 'N/A' |
| 59 |
info["{ssid}"] = string.match(output, 'ssid=([%a]+)') or 'N/A' |
| 60 |
info["{ip}"] = string.match(output, 'ip_address=([%d.]+)') or 'N/A' |
| 61 |
|
| 62 |
if not state == 'COMPLETED' then |
| 63 |
return info |
| 64 |
end |
| 65 |
|
| 66 |
local wpa_cmd = "wpa_cli -i'" .. warg .. "' bss " .. bssid .. " 2>&1" |
| 67 |
local f = io.popen(wpa_cmd) |
| 68 |
local output = f:read("*all") |
| 69 |
f:close() |
| 70 |
|
| 71 |
if not output then return info end |
| 72 |
|
| 73 |
info["{qual}"] = string.match(output, 'qual=([%d]+)') |
| 74 |
|
| 75 |
return info |
| 76 |
end |
| 77 |
|
| 78 |
|
| 79 |
return setmetatable(wpa_all, { __call = function(_, ...) return worker(...) end }) |