-------------------------- -- simple ipban script -- made on request of erik -------------------------- -- bans are stored in an external file -- use 1 IP per line -- or IP|IP for ranges -------------------------- sBanMsg = "Your ass is banned!!!" function Main() tBanIp = {} if readfrom("ipban/ipban.txt") then while 1 do local line = read() if line == nil then break end if strfind(line, "|") then local _,_,sStart,sEnd = strfind(line, "^([%.%d])|([%.%d])$") tBanIp[(IPtoDec(sStart))]=(IPtoDec(sEnd)) else tBanIp[line]=1 end end readfrom() else execute("mkdir ipban") writeto("ipban/ipban.txt") writeto() end end function IPtoDec(IP) local s,e,dIP1,dIP2,dIP3,dIP4 = strfind(IP, "^(%d+)%.(%d+)%.(%d+)%.(%d+)$") IP = (tonumber(dIP1) * 16777216) + (tonumber(dIP2) *65536) + (tonumber(dIP3) * 256) + (tonumber(dIP4)) return IP end function NewUserConnected(user) if tBanIp[user.sIP] then user:SendData(sBanMsg) user:Disconnect() else local sIp = IPtoDec(user.sIP) for a,b in tBanIp do if b ~= 1 and sIp >= a and sIp <= b then user:SendData(sBanMsg) user:Disconnect() end end end end