Forum Discussion

vishwajeet_hol's avatar
10 years ago

Get country by IP address.

Hi,

 

I want to find the country based on IP address of logged in user's machine.

I can get IP address using one of this :

1. http://communitydomain/restapi/vc/users/id/useridgoeshere/settings/name/user.last_visit_ipaddress

2. ${http.request.remoteAddr}

 

Need to check from which country it is associated.

NOTE - We can not use google API. Because it is banned in some countries.

 

Please let me know if there is any way.

 

Thanks,

Vishwajeet

  • Hi vishwajeet_hol.

    One of our developers ended up calling an external php application that uses the GEOIP module and returns the country code for a given IP address.

    The code looks something like this:

     

    <#assign response = http.client.request( "http", "example.com", "/geoip.php?ip=${http.request.remoteAddr}").get() />
    <#if response.content??>
        <#assign country = response.content>
    </#if>

    Hope this helps.

    Nic