Free, unlimited IP address geolocation with MySQL

There are a lot of services and datasets that provide IP address geolocation, allowing you to detect a web user's city of origin based on their incoming IP. Unfortunately, most of these services cost quite a bit of money, impose limits on how many lookups you can do over a period of time, or aren't kept up to date with accurate information.

I came across a great resource today, put together by Marc-Andre Caron. He's done all the necessary legwork to solve this problem, putting together a free, monthly-updated MySQL dataset that will allow you to derive country, region, city, zip, latitude, and longitude from an IP address.

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;

Keep in mind that the accuracy of the data is usually down to the location of a user's ISP. Don't expect this to get you down to a street address, but if you want to display relevant content at a city, state, or country level, this will do the trick the vast majority of the time.

IP address geolocation SQL database


Recent Entries

Comments

Oldest comments listed first.

Posted by: ehrichweiss on March 24, 2009 at 7:57 AM

AWESOME!!!

I've seen these but never got to use them since they're usually expensive. There are free ones but they don't usually tell more than the country an IP is in. This one is awesome. The guy even gives a way to block entire countries so maybe those Turkish website defacers will have some more probs(at least until they turn to Tor I guess)


Posted by: A on March 24, 2009 at 11:09 AM

I found a great free one: ip-adress.com (only one d in address). It lets you have 3 lookups per day free, but if you get an account, you get 50. It's fairly accurate, and it's what I use. Although, if you need to look up more than 50, or want some way to automate it, then that's not the site for you.


Posted by: ahamed on April 20, 2009 at 10:18 PM

hi, I found a free checkup ip details from www.ip-details.com. Its very easy to checkup our ip address, downloading and uploading speed, etc.


Posted by: 2bithacker on March 24, 2009 at 2:49 PM

You know, IP addresses are just numbers to start with. The dotted-quad notation is just to make them easier for humans to deal with. MySQL has a built-in set of functions, inet_aton() and inet_ntoa() which convert IP address strings to/from their corresponding integers.

To get the equivalent integer from an IP using these functions;

mysql> select truncate( inet_aton("74.125.45.100") / 256, 0 );
+-------------------------------------------------+
| truncate( inet_aton("74.125.45.100") / 256, 0 ) |
+-------------------------------------------------+
| 4881709 |
+-------------------------------------------------+
1 row in set (0.00 sec)


Posted by: Tim G. on April 10, 2009 at 12:10 PM

Looks like they slightly modified the formula

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

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


Posted by: kanaga.myopenid.com on June 18, 2009 at 11:31 PM

find the geo location using ip address

hai,
It's nice way to find the geolocation using my sql.
There is a site called http://www.ip-details.com/. It is used to find the geo location using ip address.


Posted by: geolocation on January 18, 2010 at 1:30 PM

IP Address geolocation

I found a new site to check out IP Address details through
www.ipaddressgeolocation.com


Leave a comment


Subscribe to MAKE!Subscribe to MAKE Magazine!

Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.

$34.95 / 1 year
(4 Quarterly Issues)

Subscribe now


Void your warranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out. Make: The risk-takers, the doers, the makers of things... Welcome to Make: Online!


CRAFT Maker Shed Maker Faire Makers Market




Check out more videos from MAKE.



MZ_MakingDetroit-RR.gif

MZ_MakeProjectsLibrary-RR.gif

Makezine: July is for Kids!


Connect with MAKE

Be a MAKE fan on Facebook MAKE on Facebook
Visit our Facebook page and become a fan of MAKE!
MAKE on Twitter MAKE on Twitter
Follow our MAKE tweets!
MAKE Flickr Pool MAKE on Flickr
Join our MAKE Flickr Pool!
    make_tips on Twitter



    MAKE Archives

    Makers Market
    Maker SHED
    Make: Science Room

    Subscribe to MAKE Magazine!

    Make: Online editors and authors!

    Gareth BranwynGareth Branwyn
    Editor-in-Chief


    Phillip TorronePhillip Torrone
    Senior Editor
    | Web | Twitter


    Becky SternBecky Stern
    Associate Editor
    | AIM | Twitter


    Marc de VinckMarc de Vinck
    Contributing Writer
    | AIM | Twitter


    John ParkJohn Park
    Contributing Writer
    | Twitter


    Sean RaganSean Ragan
    Contributing Writer
    | Twitter


    Matt MetsMatt Mets
    Contributing Writer
    | AIM | Twitter


    Dale DoughertyDale Dougherty
    Editor & Publisher
    | Twitter


    Shawn ConnallyShawn Connally
    Director of
    Digital Media
    | Twitter


    Goli MohammadiGoli Mohammadi
    Senior Editor


    Kip KayKip Kay
    Weekend Projects
    | AIM | Twitter


    Collin CunninghamCollin Cunningham
    Contributing Writer
    | AIM | Twitter

    Adam FlahertyAdam Flaherty
    Contributing Writer
    | AIM | Twitter


    John BaichtalJohn Baichtal
    Contributing Writer
    | AIM | Twitter



    More contributors: Mark Frauenfelder (Editor-in-Chief, MAKE magazine), Kipp Bradford (Technical Consultant/Writer), Chris Connors (Education), Diana Eng (Guest Author), Peter Horvath (Intern), Brian Jepson (O'Reilly Media), Robert Bruce Thompson (Science Room)

    Suggest a Site!

    Advertise here with FM.

    Why advertise on MAKE?
    Read what folks are saying about us!

    Click here to advertise on MAKE!



    Current Podcast

    itunesdl.gif Industrial Sound Controllers Tristan Shone rolled out the 'big guns' for Maker Faire Bay Area 2010. His Industrial Sound Controllers are a musical force to be reckoned with and their sheer size and weight demand considerable attention upon seeing them firsthand. Tristan... More...

    Get the Make: Online sent via email
    Enter your email to receive Make: Online each day:



    Sign up for the Make: Newsletter

    Our Make: Newsletter covers news from maker Media, has original columns, Shed deals, and more! You can also read the archives of past issues.


     



    Make: Education
    MAKE: en EspaƱol MAKE: Japan
    Important please read


    Subscribe to MAKE Magazine!

    Recent Posts from the Craft: Blog