[Include] GeoIP - lite version (without any databases)
#10

Quote:
Originally Posted by PT
Посмотреть сообщение
You could share with us
Sure here is the python script simply run it on your servers shell I didn't write this it was downloaded but modified slightly for SA-MP.

http://pastebin.com/nYtU0Zs7

Here is a function for making a geoip query, it is done using sqlitei but can easily be re-written without it.

Код:
// Stock function for retrieving GeoIP data
stock GetGeoIP(ip, country_code[3], country[32], region_code[32], region[64], city[64], zipcode[16], lat[16], lng[16], metro[16], area[16])
{
	if (!query[0])
	{
 		strimplode(" ",
   				query,
	            sizeof(query),
	            "SELECT",
             	"`city_location`.`country_code`,",
              	"`country_blocks`.`country_name`,",
               	"`city_location`.`region_code`,",
                "`region_names`.`region_name`,",
                "`city_location`.`city_name`,",
                "`city_location`.`postal_code`,",
                "`city_location`.`latitude`,",
                "`city_location`.`longitude`,",
                "`city_location`.`metro_code`,",
                "`city_location`.`area_code`",
                "FROM `city_blocks`",
                "NATURAL JOIN `city_location`",
                "INNER JOIN  `country_blocks` ON `city_location`.`country_code` = `country_blocks`.`country_code`",
                "LEFT OUTER JOIN",
                "`region_names` ON `city_location`.`country_code` = `region_names`.`country_code`",
                "AND `city_location`.`region_code` = `region_names`.`region_code`",
                "WHERE `city_blocks`.`ip_start` <= ?",
                "ORDER BY `city_blocks`.`ip_start`",
                "DESC ",
                "LIMIT 1");
		stmt = db_prepare(GeoIP, query);
	}
	
	// Bind DB Results to DB Variables
	stmt_bind_result_field(stmt, 0, DB::TYPE_STRING, country_code, sizeof(country_code));
	stmt_bind_result_field(stmt, 1, DB::TYPE_STRING, country, sizeof(country));
	stmt_bind_result_field(stmt, 2, DB::TYPE_STRING, region_code, sizeof(region_code));
	stmt_bind_result_field(stmt, 3, DB::TYPE_STRING, region, sizeof(region));
	stmt_bind_result_field(stmt, 4, DB::TYPE_STRING, city, sizeof(city));
	stmt_bind_result_field(stmt, 5, DB::TYPE_STRING, zipcode, sizeof(zipcode));
	stmt_bind_result_field(stmt, 6, DB::TYPE_STRING, lat, sizeof(lat));
	stmt_bind_result_field(stmt, 7, DB::TYPE_STRING, lng, sizeof(lng));
	stmt_bind_result_field(stmt, 8, DB::TYPE_STRING, metro, sizeof(metro));
	stmt_bind_result_field(stmt, 9, DB::TYPE_STRING, area, sizeof(area));

	// Set the IP for the query
	stmt_bind_value(stmt, 0, DB::TYPE_UINT, ip);

	// Execute DB Query
	if (stmt_execute(stmt))
	{
		// Found a result
	    if (stmt_fetch_row(stmt)) return 1;
	}
	return 0;
}
The database uses longips so you need this function.

Код:
// Get InterIP - Slice
stock GetIntegerIP(const input[])
{
    new ip = 0, pos = -1;

    for (new i = 24; i >= 0; i -= 8) {
        ip |= strval(input[++pos]) << i;

        if (i) {
            pos = strfind(input, ".", _, pos);
        }
    }
    return ip;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)