MySQL DIY – How to Apply IP Geo-Location Using MySQL!

Here’s a great resource for IP geo-location, there’s a guy who’s made a MySQL table for it, so all you need to do is check the IP address against the database.  I have personally been thinking of making such a site and this is going to help me do that, awesome!  I hope it helps you too.

The IP addresses are listed in table ip_group_city. The data is not in the 1.1.1.1 format since it would need to be stored as text and we dont want that for obvious reasons.
Let say for ip A.B.C.D, the formula is
ip = (A*256+B)*256+C
(I assume A.B.C.0 is at the same location than A.B.C.255)

For example, if you have an ip of 74.125.45.100 (google.com)

The formula would give a result of :
ip = (74*256+125)*256+45 = 4881709

You would search for the IP address using MySQL by doing :
SELECT * FROM `ip_group_city` where `ip_start` <= 4881709 order by ip_start desc limit 1;

via make

Leave a Reply

Your email address will not be published.


Other interesting stuff at Zedomax.com: , , , , , ,
Check out more interesting categories: Computer, Consumer, DIY, Educational, Featured DIYs, Hack, HOWTO, Misc, Projects, Web, WebApp.


Related News and Resources