Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Country according to a certain IP? [duplicate]

Tags:

lookup

ip

country

Does anyone know any simple way to retrieve the country from a given IP Address, preferably in ISO_3166-1 format?

like image 675
DylanJ Avatar asked Aug 04 '08 05:08

DylanJ


People also ask

Can you identify country by IP address?

Imp You can't get the country "just by looking at an IP address". Our service, IPinfo.io, infers the geographic location of IPs by pulling in many different data sources, and performing active scans across all IP addresses, and then publishes the results daily.

How do you find what country an IP is from?

You may also use 3rd party websites such as Geobytes or Dnsstuff to lookup the IP address. The whois lookup will reveal name of the ISP who owns that IP address, and the country where it is originated from. If you're lucky, you might also find the city of orgin.


1 Answers

There are two approaches: using an Internet service and using some kind of local list (perhaps wrapped in a library). What you want will depend on what you are building.

For services:

  • http://www.hostip.info/use.html (as mentioned by Mark)
  • http://www.team-cymru.org/Services/ip-to-asn.html

For lists:

  • http://www.maxmind.com/app/geoip_country (as mentioned by Orion)
  • You could roll your own by downloading the lists from the RIRs:

    • ftp.arin.net/pub/stats/arin/delegated-arin-latest
    • ftp.ripe.net/ripe/stats/delegated-ripencc-latest
    • ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest
    • ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest
    • ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest

      The format is documented in this README

like image 142
Warren Blanchet Avatar answered Sep 21 '22 04:09

Warren Blanchet