Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@uplink:~# cat /tmp/iwinfo-json.lua
- #!/usr/bin/lua
- local iw = require "iwinfo"
- local dev = arg[1] or "wlan0"
- function write_json(x)
- if x == nil then
- io.write("null")
- elseif type(x) == "table" then
- local k, v
- if type(next(x)) == "number" then
- io.write("[ ")
- for k, v in ipairs(x) do
- write_json(v)
- if next(x, k) then
- io.write(", ")
- end
- end
- io.write(" ]")
- else
- io.write("{ ")
- for k, v in pairs(x) do
- io.write(string.format("%q: ", k))
- write_json(v)
- if next(x, k) then
- io.write(", ")
- end
- end
- io.write(" }")
- end
- elseif type(x) == "number" or type(x) == "boolean" then
- if (x ~= x) then
- -- NaN is the only value that doesn't equal to itself.
- io.write("Number.NaN")
- else
- io.write(tostring(x))
- end
- else
- io.write(string.format('"%s"', tostring(x):gsub('["%z\1-\31]', function(c)
- return '\u%04x' % c:byte(1)
- end)))
- end
- end
- local backend = iw.type(dev)
- if not backend then
- error("No such wireless device:", dev)
- end
- local info = { }
- local _, field
- for _, field in ipairs({
- "ssid", "bssid", "mode", "channel", "frequency",
- "txpower", "quality", "quality_max",
- "signal", "noise", "bitrate", "encryption",
- "hwmodelist", "assoclist"
- }) do
- info[field] = iw[backend][field](dev)
- end
- write_json(info)
- root@uplink:~# lua /tmp/iwinfo-json.lua wlan1
- { "quality_max": 70, "ssid": "Funkueberwachungswagen 5", "encryption": { "enabled": true, "auth_algs": [ "OPEN" ], "description": "WPA2 PSK (CCMP)", "wep": false, "auth_suites": [ "PSK" ], "wpa": 2, "pair_ciphers": [ "CCMP" ], "group_ciphers": [ "CCMP" ] }, "assoclist": { "00:15:61:10:51:DF": { "rx_short_gi": true, "noise": -95, "rx_mcs": 5, "tx_40mhz": true, "rx_40mhz": true, "tx_rate": 108000, "tx_packets": 739361, "tx_short_gi": false, "rx_packets": 402970, "tx_mcs": 11, "inactive": 2060, "rx_rate": 120000, "signal": -75 } }, "bssid": "C0:3F:0E:7A:A0:96", "hwmodelist": { "a": true, "n": true, "g": false, "b": false }, "bitrate": 108000, "txpower": 17, "noise": -95, "channel": 149, "signal": -75, "mode": "Master", "quality": 35, "frequency": 5745 }
- root@uplink:~#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement