一个openwrt无线踢人的脚本, 模拟ubnt的踢人,原理根据:iw dev wlan0 station del mac ,本想用openwrt里的sh脚本命令实现,但原来openwrt的sh的脚本命令是ash来的,实现起来麻烦,于是用lua脚本实现,操作非常方便.
废话不说,以下是脚本:
function split(s, delim) if type(delim) ~= "string" or string.len(delim) <= 0 then return end local start = 1 local t = {} while true do local pos = string.find (s, delim, start, true) -- plain find if not pos then break end table.insert (t, string.sub (s, start, pos - 1)) start = pos + string.len (delim) end table.insert (t, string.sub (s, start)) return t end local find = string.find local sub = string.sub function trim8(s) local i1,i2 = find(s,'^%s*') if i2 >= i1 then s = sub(s,i2+1) end local i1,i2 = find(s,'%s*$') if i2 >= i1 then s = sub(s,1,i1-1) end return s end local ming = io.popen('iw dev | grep Interface | cut -f 2 -s -d" "') local getstr = ming:read("*all") local gg="" aaa=split(getstr,"\n") local shu=#aaa-1 for i=1,#aaa-1 do cc=aaa[i] gg=gg.."iw dev "..cc.." station dump;" end local mingling=gg local t = io.popen(mingling) local a = t:read("*all") --print(a) --astring= "----分割?--" --print(astring) aa=split(a,"TDLS peer") for i=1,#aa-1 do bb=aa[i] cc = split(bb,"(on") dd = cc[1] ee = split(dd, "Station") ff = trim8(ee[2]) --print(ff) ii=find(bb, "[-",1,true) if ii ~=nil then cc2 = split(bb," [-") else cc2 = split(bb," dBm") end dd2 = split(cc2[1],"signal: ") ee2 = trim8(dd2[2]) --print(ee2) ee3 = tonumber(ee2) ccc = split(bb, "wlan") ddd = split(ccc[2],")") eee = "wlan"..ddd[1] --print(eee) if ee3 < -81 then datex=os.date("%Y-%m-%d %H:%M:%S"); print("ti ren: "..datex) os.execute("iw dev "..eee.." station del "..ff) print("iw dev "..eee.." Station del "..ff) end --print("----") end
做成脚本,再定时任务哪里设置,每5分钟执行一次, 在任务里填写:
*/5 * * * * /usr/bin/lua /root/tiren.lua >>/tmp/dellist.txt &
现在是小于-81db就删掉,这样无线连接效果好很多。
另外想说的就是lua脚本操作起来还是很方便,容易上手呢。
本站的文章和资源来自互联网或者站长的原创,按照 CC BY -NC -SA 3.0 CN协议发布和共享,转载或引用本站文章应遵循相同协议。如果有侵犯版权的资 源请尽快联系站长,我们会在24h内删除有争议的资源。欢迎大家多多交流,期待共同学习进步。