Does anyone know any simple way to retrieve the country from a given IP Address, preferably in ISO_3166-1 format?
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.
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.
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:
For lists:
You could roll your own by downloading the lists from the RIRs:
ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest
The format is documented in this README
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With