Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add bssid return; automaticlly choose the wpa_cli path

  • Loading branch information...
commit 4c7015b114f9232f9f967ff95702bce6891093d4 1 parent 488c795
@jinleileiking authored
Showing with 15 additions and 8 deletions.
  1. +1 −0  contrib/README
  2. +14 −8 contrib/wpa.lua
View
1  contrib/README
@@ -90,6 +90,7 @@ vicious.contrib.wpa
- $1 returns the ssid your wireless lan is connecting
- $2 returns the quality of your wireless lan
- $3 returns the ip of your wireless lan
+ - $4 returns the bssid of your wireless lan
Usage examples
--------------
View
22 contrib/wpa.lua
@@ -26,26 +26,32 @@ module("vicious.contrib.wpa")
-- {{{ Wireless widget type
local function worker(format, warg)
- na = {'N/A', 'N/A', 'N/A'}
+ na = {'N/A', 'N/A', 'N/A', 'N/A'}
if not warg then return na end
- local wpa_cmd = "/usr/bin/wpa_cli -i" .. warg .. " status 2>&1"
+ local f = io.popen("which wpa_cli")
+ local wpa_cli = f:read("*all")
+ f:close()
+
+ wpa_cli = string.match(wpa_cli, '([%a/_]+)')
+
+ local wpa_cmd = wpa_cli .. " -i" .. warg .. " status 2>&1"
local f = io.popen(wpa_cmd)
local output = f:read("*all")
f:close()
if not output then return na end
- state = string.match(output, 'wpa_state=([%a]+)')
- bssid = string.match(output, 'bssid=([%d%a:]+)')
- ssid = string.match(output, 'ssid=([%a]+)')
+ state = string.match(output, 'wpa_state=([%a]+)') or 'N/A'
+ bssid = string.match(output, 'bssid=([%d%a:]+)') or 'N/A'
+ ssid = string.match(output, 'ssid=([%a]+)') or 'N/A'
ip = string.match(output, 'ip_address=([%d.]+)') or 'N/A'
if not state == 'COMPLETED' then
- return {'N/A', 'N/A', 'N/A'}
+ return na
end
- local wpa_cmd = "/usr/bin/wpa_cli -i" .. warg .. " bss " .. bssid .. " 2>&1"
+ local wpa_cmd = wpa_cli .. " -i" .. warg .. " bss " .. bssid .. " 2>&1"
local f = io.popen(wpa_cmd)
local output = f:read("*all")
f:close()
@@ -54,7 +60,7 @@ local function worker(format, warg)
qual = string.match(output, 'qual=([%d]+)')
- return {ssid, qual, ip}
+ return {ssid, qual, ip, bssid}
end
-- }}}
Please sign in to comment.
Something went wrong with that request. Please try again.