Which country did a user request come from? How can I determ


Can anybody recommend a means to determine the country that an incoming
request is originating from?

I’m guessing that you would first get the IP from the HTTP header and
somehow translate this? Is there a service that can be used for this?
there a set of rules that one can use to implement within your rails
application? Any advice welcome, even if the best possible is only a
accuracy thing.

Thanks in advance

PS Meant to ask too whether a rails plugin exists for this, and whether
this can be done for free (i.e. without having to pay to subscribe to a

Yap, use GeoIP gem (look in www.gemjack.com). the free version will
reply to you with a country.

works great, i use it myself in one project.

Any idea why the following fails?

$ ls -l /usr/share/GeoIP/GeoIP.dat
-rwxr-xr-x 1 root wheel 682474 Jan 13 09:17

$ cat a.rb
require ‘geoip’
p GeoIP.new(’/usr/share/GeoIP/GeoIP.dat’).country(“www.netscape.sk”)

$ RUBYOPT=rubygems ruby a.rb
getaddress': getaddrinfo: No address associated with nodename (SocketError) from /usr/lib/ruby/gems/1.8/gems/geoip-0.3.0/lib/geoip.rb:273:incountry’
from a.rb:2

(Replying to self). The problem is that www.netscape.sk does not
exist. The code works with existing sites. Sorry for the confusion…

thanks for the reply Elad - I’ll have a look right now - how accurate do
find www.gemjack.com to be?