Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local handler = mysql_connect("185.180.230.29", "geoip", "WTAqquYRMTQmNKvK", "geoip");
- local Player = {};
- function OnFilterscriptInit()
- MySQLInit();
- test(0);
- end
- function MySQLInit()
- if not(handler) then
- LogString("Logs_MySQL","Unable connect to database");
- else
- LogString("Logs_MySQL","Connected: ", handler);
- end
- end
- function checkMySQLConnection()
- if (mysql_ping(handler) == false) then
- return false;
- end
- return true;
- end
- function reconnectMySQL()
- LogString("Logs_MySQL","Lost connection to database. Reconnecting...");
- mysql_close(handler);
- handler = mysql_connect("185.180.230.29", "geoip", "WTAqquYRMTQmNKvK", "geoip");
- end
- function OnPlayerConnect(playerid)
- if IsNPC(playerid) == 0 then
- if checkMySQLConnection() == true then
- if IsPlayerConnected(playerid) == 1 then
- --ั ะตั
- end
- else
- reconnectMySQL();
- end
- end
- end
- function test(playerid)
- local Player = {};
- Player.Row = nil;
- local _ip = "70.25.96.9";
- local ip1,ip2,ip3,ip4 = string.match(_ip, "(%d+).(%d+).(%d+).(%d+)"); --1.0.1.0 70.25.96.95
- local table_amount = "SELECT COUNT(*) FROM `mytable` WHERE `IP1` LIKE '"..ip1..".%' AND `IP1` LIKE '%."..ip2..".%' OR `IP2` LIKE '"..ip1..".%' AND `IP2` LIKE '%."..ip2..".%'"; --70.25.96.80 - 70.25.96.95
- local result = mysql_query(handler, table_amount);
- if not(result) then
- else
- local rows = {};
- local amount = mysql_fetch_row(result);
- mysql_free_result(result);
- result = mysql_query ( handler, "SELECT * FROM `mytable` WHERE `IP1` LIKE '"..ip1..".%' AND `IP1` LIKE '%."..ip2..".%' OR `IP2` LIKE '"..ip1..".%' AND `IP2` LIKE '%."..ip2..".%'");
- for i = 1, amount[1] do
- local row = mysql_fetch_assoc(result);
- table.insert(rows, row);
- for key,value in pairs(rows) do
- local q1,q2,q3,q4 = string.match(rows[key]["IP1"], "(%d+).(%d+).(%d+).(%d+)");
- local s1,s2,s3,s4 = string.match(rows[key]["IP2"], "(%d+).(%d+).(%d+).(%d+)");
- if ((ip1 >= q1 and ip1 <= s1) and (ip2 >= q2 and ip2 <= s2) and (ip3 >= q3 and ip3 <= s3) and (ip4 >= q4 and ip4 <= s4)) then
- LogString("GeoIP_Log","IP ".._ip.." founded. It belongs to "..rows[key]["country_name"]..".");
- else
- LogString("GeoIP_Log","IP ".._ip.." not founded.");
- end
- end
- end
- mysql_free_result(result);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement