Код
require ("luasql.mysql")
local env = luasql.mysql()
conn = env:connect(tMySQL.DB,tMySQL.User,tMySQL.Pass,tMySQL.Host,tMySQL.Port)
conn:execute("SET NAMES "..tMySQL.Charset)
function string.iptonumber(ip)
local i1, i2, i3, i4 = ip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
if i1 then
return i1*16777216+i2*65536+i3*256+i4
end
end
function ip_getinfo(ip)
if ip then
ip = ip:iptonumber()
end
local res = assert(conn:execute("SELECT * FROM "..tMySQL.Prefix.."providers WHERE "..ip..
" BETWEEN `start_ip` AND `end_ip` LIMIT 1")
):fetch({}, "a")
if res then
return res.country,res.name,res.site, res.city
else
return "n/a"
end
end