What is the most applicable solution to detect which country an ip belongs to?

空扰寡人 提交于 2020-01-17 03:42:10

问题


Someone recommended cdn,

And is it accurate in judging where the IP address belong to?

How is it done?

Is there a better solution?


回答1:


Try hitting the pidgets geoip service (it uses the maxmind database)

http://geoip.pidgets.com




回答2:


There no fixed rules that can tell you which IP belongs to which country. It depends on which company owns the IP range at a given time and therefore can change as the ownership changes. You therefore either need to keep up an up to date database about which company owns which IP range yourself or you rent access to such a database.




回答3:


Not sure what the link of a CDN and ip/geo lookup is. However, if you use a cdn to deliver content, they will provide reporting on where the users are coming from. See my blog post for more details on CDNs.

Regarding looking up a user's country from their IP. There are a couple ways to do this. It is fairly acurate. I'd certainly say it is accurate "enough." If you simply want to lookup the country of a few IPs. Go to a site like dnsstuff.com and they have online tools for doing that. If you want to programatically do this, use a service like Maxmind or digital envoy. Maxmind is the much cheaper option.




回答4:


You can do a GET request to this URL: https://api.teletext.io/api/v1/geo-ip and it will respond with some country information in JSON format.

If you want to implement it yourself: I've set this up by using AWS Cloudfront, Cloudfront adds a header (Cloudfront-Viewer-Country) to your request before it forwards it to the origin server that you can use. Make sure to whitelist the header in your Cloudfront distribution.



来源:https://stackoverflow.com/questions/1451442/what-is-the-most-applicable-solution-to-detect-which-country-an-ip-belongs-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!