How to determine the user’s approximate location by IP?

Asked

Viewed 8,812 times

26

When I use search engines for certain searches, mainly related to maps or commercial establishments, these systems usually serve me results relevant to my geographical location.

When I’m on the PC, search engines may not even know my geographic position with GPS accuracy, but at least they know what city I’m in.

I believe this is determined by the IP address, since usually a specific address range is provided by the provider for well-defined regions.

But at the implementation level, how is this determination made? Is there a formula to determine the user’s city or region from its address? Or at least one known provider from which we may consume a service to obtain that information?

  • 4

    I remembered at the time of that XKCD... Unfortunately I couldn’t find any information either on the forum, blog post or Slashdot about how this map was made (I didn’t dig deep enough, though). And from what I read here, most IP geolocation databases are commercial (paid), and their quality varies greatly.

  • 1

    It doesn’t answer your question, but it could be a start. I found here a country/IP band ratio.

  • 1

    It is also worth remembering that this information is organic (changes frequently) and ad hoc (the distribution of ips is done by ICANN and the databases available there are built part with this ICANN database and part through statistical samples). This means that the best geoip service offers no more than 90 to 95% country security and no more than 80-90% city information.

3 answers

8

IP GEOLOCATION

This is actually very simple and works as follows:

7


Take a look here: http://php.net/manual/en/function.geoip-record-by-name.php

We use this on our website (www.ansb-brasil.org). If u write using the contact form, when the site thanks you, it indicates the IP, the country, and the city of you.

Actually, this doesn’t exactly give you the name of your city, but the name of your internet access point.

  • The fact that this is an official PHP function cheers me up. I will test from home later :)

  • Beware; before using, make a "Phpinfo()" to see if the PHP you have, has this possibility. Also, there are hosting companies that use a different system. I am in Brasilia but we use a European hosting that offers a slightly different system than Geiop (we have $_SERVER[GEOIP] for example)

6

I don’t mean to jab, but already, I have a library called WallaceMaxters\IPInfo, that takes information from a particular IP.

See an example of use:

 IPInfo::get('8.8.8.8')->getCountry();

It internally uses the ipinfo.io.

If you want an example, go to the url below to capture the information:

http://ipinfo.io/8.8.8.8/json

As stated in previous answers, you cannot determine the exact location of the person. Maybe just approximated or even just within the country.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.