分类: 系统运维
2009-04-11 07:40:26
ip = ((A*256+B)*256+C)*256
ip = ((74*256+125)*256+45)*256 = 1249717504
SELECT * FROM `ip_group_city` where `ip_start` <= INET_ATON('74.125.45.100') order by ip_start desc limit 1;
SELECT * FROM `ip_group_city` where `ip_start` <= 1249717504 order by ip_start desc limit 1;
ip_start|country_code|region_code|city|zipcode|latitude|longitude
1249717504|US|CA|Mountain View|94043|37.4192|-122.057
Note : The ISO 3166 format is used for country code.
Using table ip_group_country you can do 2 things.
First, would be to locate an IP simply by country.
You would search this way :
SELECT * FROM `ip_group_country` where `ip_start` <= INET_ATON('74.125.45.100') order by ip_start desc limit 1;
Or
SELECT * FROM `ip_group_country` where `ip_start` <= 1249717504 order by ip_start desc limit 1;
Second, you might want to get the IP of a specific country to generate a blocklist with iptable, htaccess file or whatever you use. It would be done like this :
SELECT `ip_cidr` FROM `ip_group_country` WHERE `country_code` = 'AF' order by ip_start;
which would give you something like this :
63.243.149.0/24
67.212.160.0/24
80.247.139.0/24
82.205.190.0/21
82.205.198.0/23
[...]
Let me explain. Let say ips 74.125.0.XXX to 74.125.32.XXX have the same location (owned by google for example). I didn't store 32 times the same information, the database would have been huge for no reason. I stored only 74.125.0.XXX. The end of the block is the next row which would be 74.125.33.XXX
Yes we do. Please visit this
Most of the data in Blogama IP Geolocation database is from Geolite City but it's optimized without compromising accuracy. The difference is 1.4 millions entries in our database compared to 3 millions in Maxmind one which means faster queries. Also, there is a table in our database with IP by country grouping (around 75000 entries) if you need less details on the geolocation. It takes around 2 days to generate the complete database.