How to get country for given IP address using API

Martin Dobsicek asked on September 14, 2009 16:05

How to get country for given IP address using API

Correct Answer

Martin Dobsicek answered on September 14, 2009 16:05

You can use sample code below:

        // Converts IP4 address to country name.
        CMS.WebAnalytics.IP2CountryHelper ip2country = new CMS.WebAnalytics.IP2CountryHelper();
        string country = ip2country.GetCountryByIp("<IP>");

Since version 5.5 of Kentico CMS IP2CountryHelper class is static. Therefore, you need to use following code instead:

        string country = IP2CountryHelper.GetCountryByIp(
"<IP>");

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.