Block connections from specified countries or regions

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

Block connections from specified countries or regions

Post by FTP »

If you want to block connections from specified countries or regions, you can insert the following script into the event "Event Manager > FTP/HTTP/SSH Events > BeforeUserLoggedIn":

Code: Select all

local handle = io.popen("curl http://ip-api.com/line/%IP")
local strResult = handle:read("*a")
handle:close()
if strResult ~= nil and strResult ~= "" then
  local arrResult = Split(strResult, "\n")
  if table.maxn(arrResult) > 1 and arrResult[1] == "success" then
    local country = arrResult[2]
    local bannedCountries = "Country1, Country2, Country3"
    if string.find(bannedCountries, country) then
      bCancelEvent = true
      return
    end 
  end
end
Just replace the string "Country1, Country2, Country3" into the real country/region names you want to block.
And you can find all the country/region names from this web page: https://www.iplocate.com/en/resources/countries
Post Reply