Created
May 29, 2012 05:56
-
-
Save Mic92/2822851 to your computer and use it in GitHub Desktop.
vicious wpa.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e5630c1c1ab083af6dc0a956a35c2e0e609c87bc Mon Sep 17 00:00:00 2001 | |
From: jinleileiking <jinleileiking@gmail.com> | |
Date: Wed, 30 May 2012 17:16:13 +0200 | |
Subject: [PATCH] add wpa widget | |
--- | |
contrib/README | 6 +++++ | |
contrib/wpa.lua | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
2 Dateien geändert, 73 Zeilen hinzugefügt(+) | |
create mode 100644 contrib/wpa.lua | |
diff --git a/contrib/README b/contrib/README | |
index 010cfc3..b093b08 100644 | |
--- a/contrib/README | |
+++ b/contrib/README | |
@@ -83,6 +83,12 @@ vicious.contrib.rss | |
vicious.contrib.sensors | |
- | |
+vicious.contrib.wpa | |
+- provides information about the wifi status | |
+- requires 'wpa_cli' from wpa_supplicant | |
+- takes the interface as an argument, i.e "wlan0" or "wlan1" | |
+- returns a table with string keys: {ssid}, {qual}, {ip}, {bssid} | |
+ | |
Usage examples | |
-------------- | |
diff --git a/contrib/wpa.lua b/contrib/wpa.lua | |
new file mode 100644 | |
index 0000000..a6ec70f | |
--- /dev/null | |
+++ b/contrib/wpa.lua | |
@@ -0,0 +1,67 @@ | |
+--------------------------------------------------- | |
+-- Licensed under the GNU General Public License v2 | |
+-- * (c) 2012, jinleileiking. <jinleileiking@gmail.com> | |
+--------------------------------------------------- | |
+ | |
+-- {{{ Grab environment | |
+local tonumber = tonumber | |
+local math = { ceil = math.ceil } | |
+local setmetatable = setmetatable | |
+local helpers = require("vicious.helpers") | |
+local io = { | |
+ open = io.open, | |
+ popen = io.popen | |
+} | |
+local string = { | |
+ find = string.find, | |
+ match = string.match | |
+} | |
+-- }}} | |
+ | |
+ | |
+-- Wifi: provides wireless information for a requested interface | |
+module("vicious.contrib.wpa") | |
+ | |
+local info = { | |
+ ["{ssid}"] = "N/A", | |
+ ["{bssid}"] = "N/A", | |
+ ["{ip}"] = "N/A", | |
+ ["{qual}"] = "N/A", | |
+} | |
+ | |
+-- {{{ Wireless widget type | |
+local function worker(format, warg) | |
+ if not warg then return info end | |
+ | |
+ 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 info end | |
+ | |
+ state = string.match(output, 'wpa_state=([%a]+)') or 'N/A' | |
+ info["{bssid}"] = string.match(output, 'bssid=([%d%a:]+)') or 'N/A' | |
+ info["{ssid}"] = string.match(output, 'ssid=([%a]+)') or 'N/A' | |
+ info["{ip}"] = string.match(output, 'ip_address=([%d.]+)') or 'N/A' | |
+ | |
+ if not state == 'COMPLETED' then | |
+ return info | |
+ end | |
+ | |
+ local wpa_cmd = "wpa_cli -i'" .. warg .. "' bss " .. bssid .. " 2>&1" | |
+ local f = io.popen(wpa_cmd) | |
+ local output = f:read("*all") | |
+ f:close() | |
+ | |
+ if not output then return info end | |
+ | |
+ info["{qual}"] = string.match(output, 'qual=([%d]+)') | |
+ | |
+ return info | |
+end | |
+-- }}} | |
+ | |
+setmetatable(_M, { __call = function(_, ...) return worker(...) end }) | |
+ | |
+ | |
-- | |
1.7.10.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment