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)

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

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)
   table.insert(domain_ipmasks, {strIP, true})

c_SetIPMaskList(domain, domain_ipmasks)

And the content of IP access rules file will look like this:

Code: Select all

BTW, please do not add any "allowed" IP access rules if you already have "denied" rules.
Site Admin
Tue Sep 29, 2009 6:09 am

Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 1 guest