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

by max on Wednesday, March 25th, 2009

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

Rate

1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

ad ad
ad ad


20,000 GPS POI's $9.99

Related News and Resources

Other Interesting News From Our Friends

blog comments powered by Disqus
If you like this post then please subscribe to my full feed RSS.

You can also subscribe by E-mail by filling out your name and E-mail below:

Name: Email:


Got a new hack, DIY, howto, or gadget? Tip us here.

Try Goohack to find a new Hack:


Featured Sites From Zedomax Blog Network