OpenWRT检测无线网卡失联后重启无线网卡

Created: Nov. 16, 2019, 6:30 a.m. Updated: Nov. 16, 2019, 6:30 a.m.

OpenWRT检测无线网卡失联后重启无线网卡

#!/usr/bin/lua

require "iwinfo"

local dev = "ath1"

function delay_s(delay)
        delay = delay or 1
        local time_to = os.time() + delay
        while os.time() < time_to do end
end

function sleep(n)
         os.execute("sleep " .. tonumber(n))
end

function check()
        local api = iwinfo.type(dev)
        iw = iwinfo[api]

        local res = iw.ssid(dev)
end

while (true)
do
        if pcall(check) then
                if iw.bssid(dev) == "00:00:00:00:00:00" then
--              if iw.bssid(dev) == "B4:DE:DF:2E:10:43" then
                        print("success")
                        os.execute("/sbin/wifi restart ")
                else
                        print(iw.bssid(dev))
                end
        else
                print("fail")
        end
        sleep(10)
end