Getting a user country name from originating IP address with Ruby on Rails

前端 未结 11 1701
一整个雨季
一整个雨季 2020-12-04 08:26

I want to extract a user country name from visitors\' IP addresses.

I could get the IP address with remote_ip. But what could be the easiest way to get

11条回答
  •  孤街浪徒
    2020-12-04 08:58

    I'm using this one-liner:

    locale = Timeout::timeout(5) { Net::HTTP.get_response(URI.parse('http://api.hostip.info/country.php?ip=' + request.remote_ip )).body } rescue "US"
    

提交回复
热议问题