0

I'm using ip2location service called ip2proxy PX1BIN and downloaded the file IP2PROXY-IP-COUNTRY.BIN

Here is my code:

location /check_ip {
  # access_by_lua_file /usr/local/openresty/nginx/html/default/check_ip.lua;
  default_type text/html;
  content_by_lua_block {
   ip2proxy = require('ip2proxy')
   local ip2prox = ip2proxy:open('/usr/local/ip2proxy/IP2PROXY-IP-COUNTRY.BIN')
   local result = ip2prox:get_all(ngx.var.remote_addr)
   ngx.say("IP: " .. ngx.var.remote_addr)
   ngx.say("country_short: " .. result.country_short)
   ngx.say("proxytype: " .. result.proxytype)
   ngx.say("isproxy: " .. result.isproxy)
  }
}

I have 2 problems now: 1- when I put ip2prox:close() at the end like the documentation, it shows me error that this line of code is invalid! 2- Even I have bought the database and uploaded into my server, it shows me this result:

country_short: Invalid database file
country_long: Invalid database file
...

How can I fix it? All I need is detecting VPN and Datacenter IPs in Openresty Lua.

Abdol Seed
  • 1,227
  • 1
  • 14
  • 23
  • Can you check if the file /usr/local/ip2proxy/IP2PROXY-IP-COUNTRY.BIN actually exists and that your code has sufficient permissions to read it? – Vlam Aug 02 '23 at 05:04

0 Answers0