Import IP access rules from a text file

You can share your Lua Scripts with everybody here.

Import IP access rules from a text file

Postby FTP » Fri Jul 03, 2015 10:13 am

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.
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 2 guests