IP to country

[lang_de]Dieser Eintrag ist nur auf Englisch verfügbar.[/lang_de]

If you need to find out what country an IP is in, but are forced to use PHP or some other language without proper DNS querying features (but which can do UDP), here’s a little something for you.

ip2countryd-r2.tgz 344KiB – ip2countryd revision 2
Includes the required data file (~2MiB) and the cached data (~432KiB).

Runs a daemon on UDP port 8000 (by default) that responds to an input IP address with the ISO country code of the IP’s country, or ‘error’ if anything goes wrong (no mapping, not an IP, etc.). There is a test server at udp://ubermutant.net:8000/.

$ nc -u ubermutant.net 8000
207.13.77.53
us
212.227.57.11
eu

Idea from WP-ShortStat and the associated ip2country service. I wrote this just for the fun of it and because I wanted to see how long it would take me.

Total time required: ~1 hour.