Block IP permanently after a few failed login attempts

You can share your Lua Scripts with everybody here.
Post Reply
FTP
Site Admin
Posts: 1918
Joined: Tue Sep 29, 2009 6:09 am

Block IP permanently after a few failed login attempts

Post by FTP »

First, enable the anti-hammer option under "Domain > Settings > General Settings > Password & Security > Enable Anti-hammer".

And then insert the following Lua script in the event "OnExceedUSERPASS":

Code: Select all

local ipmasks = c_GetGlobalIPMaskList()
local g_ipmasks = {}
if type(ipmasks) == "table" then
   for _,ipmask in pairs(ipmasks) do
      local temp = {}
      table.insert(temp,ipmask.ip)
      table.insert(temp,ipmask.refuse)
      table.insert(temp,ipmask.comment)
      table.insert(g_ipmasks,temp)
   end
end
table.insert(g_ipmasks,{"%IP",true})
c_SetGlobalIPMaskList(g_ipmasks)
TeamBas
Posts: 11
Joined: Wed Sep 15, 2021 8:59 am

Re: Block IP permanently after a few failed login attempts

Post by TeamBas »

And how can I reverse a ban if I have used the script?
Gallaxial
Posts: 7
Joined: Tue Jun 09, 2020 7:13 pm

Re: Block IP permanently after a few failed login attempts

Post by Gallaxial »

i got the same problem how to revese the BAN can find anywhere
FTP
Site Admin
Posts: 1918
Joined: Tue Sep 29, 2009 6:09 am

Re: Block IP permanently after a few failed login attempts

Post by FTP »

For example, if you want to remove the banned IP "192.168.31.100", you can try the following script:

Code: Select all

local ipmasks = c_GetGlobalIPMaskList()
if type(ipmasks) == "table" then
   for i,ipmask in pairs(ipmasks) do
	if ipmask.ip == "192.168.31.100" then
		table.remove(ipmasks, i)
	end
   end
end

local global_ipmasks = {}
if type(ipmasks) == "table" then
	for _,ipmask in pairs(ipmasks) do
		local temp = {}
		table.insert(temp,ipmask.ip)
		table.insert(temp,ipmask.refuse)
		table.insert(temp,ipmask.comment)
		table.insert(global_ipmasks,temp)
	end
end

c_SetGlobalIPMaskList(global_ipmasks)
Post Reply