[OpenWRT]Scan WIFI

通过lua扫描当前的无线热点状态

#!/usr/bin/lua

dev = arg[1]
local sys = require "luci.sys"
local utl = require "luci.util"
local iw = luci.sys.wifi.getiwinfo(dev)

    function scanlist(times)
        local i, k, v
        local l = { }
        local s = { }

        for i = 1, times do
            for k, v in ipairs(iw.scanlist or { }) do
                if not s[v.bssid] then
                    l[#l+1] = v
                    s[v.bssid] = true
                end
            end
        end

        return l
    end

    function format_wifi_encryption(info)
        if info.wep == true then
            return "WEP"
        elseif info.wpa > 0 then
            return string.format("Pairwise: %s / Group: %s >%s - %s",
                table.concat(info.pair_ciphers, ", "),
                table.concat(info.group_ciphers, ", "),
                (info.wpa == 3) and string.format("mixed WPA/WPA2")
                    or (info.wpa == 2 and "WPA2" or "WPA"),
                table.concat(info.auth_suites, ", ")
            )
        elseif info.enabled then
            return unknown
        else
            return open
        end
    end


for i, net in ipairs(scanlist(3)) do
    net.encryption = net.encryption or { }
    print("channel:",net.channel);
    print("ssid:",net.ssid);
    print("bssid:",net.bssid);
    print("Mode:",net.mode);
    wep=net.encryption.wep and 1 or 0
    
    print("Encryption:",format_wifi_encryption(net.encryption));
    print("");
end

使用方法:

root@OPENWRT:~# ./scanwifi.lua radio0

root@OPENWRT:~# ./scanwifi.lua radio1

原文地址:https://www.cnblogs.com/mybays/p/3446914.html