Import IP access rules from a text file

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

Import IP access rules from a text file

Post by FTP »

For importing IP access rules from a text file, you just need to use the following Lua script:

Code: Select all

local domain = "YourDomainName"
local ipmasks = c_GetIPMaskList(domain)

local domain_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(domain_ipmasks, temp)
   end
end

local fp = assert(io.open("c:/bannedIPs.txt", "rb"))
local content = fp:read("*all")
fp:close()

local arrayIP = Split(content, "\n")
for _, ip in ipairs(arrayIP) do
	local strIP = ip
	if string.sub(ip,-1) == "\r" then
	    strIP = string.sub(ip, 0, string.len(ip)-1)
	end
	table.insert(domain_ipmasks, {strIP, true})
end

c_SetIPMaskList(domain, domain_ipmasks)
And the content of IP access rules file will look like this:

Code: Select all

41.79.56.0/22
41.79.112.0/22
41.79.132.0/22
41.79.188.0/22
41.85.192.0/19
41.190.32.0/19
41.191.232.0/21
41.220.16.0/20
41.221.144.0/20
77.246.48.0/20
154.73.80.0/22
194.133.122.0/24
BTW, please do not add any "allowed" IP access rules if you already have "denied" rules.
davidroork
Posts: 1
Joined: Mon Jul 19, 2021 8:02 pm

Re: Import IP access rules from a text file

Post by davidroork »

Do I have to purchase the Corporate Edition to be able to set this event LUA script or am I doing something wrong?
I keep getting an error saying this is not available in free/standard/secure versions.
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Import IP access rules from a text file

Post by FTP »

Yes, the event feature is only supported in the Corporate edition.
Post Reply