如何通过IP地址访问用户所在国家/地区

问题描述:

亲爱的朋友们,



我有一个要求我需要找出用户的国家,他们是从不同的地方访问我们的网站。

我使用了一些web api来获取国家代码

但这些api并没有给我正确的详细信息

例如:

有时候这个函数会返回IN,有些时候是XX,我已经尝试了一些其他的Api,其中一些是应付的,其中一些做了同样的事情,不给国家代码。





Dear Friends,

I have a requirement I need to find out the country of users, they are accessing our site from different places.
I have used some web api's to get the country code
but these api's are not giving me the correct details always
for eg:
some times this function will return IN,some times XX, I have tried some other Api's also some of them are payable and some of them did the same thing not giving country code always.


static public string GetCountry()
            {
             return new WebClient().DownloadString("http://api.hostip.inf/country.php");
            }





任何人都可以建议一个正确的方法来获取访问我们网站的用户的国家。



Can anyone suggest a proper method to get the country of a user who is accessing our site.

所以最后我得到了答案

google god帮助我

So finally I got the answer
google god help me
using System.Globalization;




static public string GetCountry()
       {
          //
           return RegionInfo.CurrentRegion.DisplayName;

       }


这个问题答案很少

检查网站上的访客国家 [ ^ ]



您可以找到更多这里 [ ^ ]
This question has few answers
check visitor country on website[^]

You could find more here[^]