如何通过IP取得用户的城市或地区

想在项目中实现通过访问者IP得到该IP对应的地区或城市,有什么比较好的办法吗?

之前没有经验,想到的两种可能实现:

  • 通过网上下载的数据导入数据库,与IP比对进行分析
  • 通过接口或者直接抓取现有的网页取得结果

麻烦大家分享一下,谢谢

阅读 7.2k
4 个回答

纯真ip库.

纯真ip库;

$ curl ifconfig.me ⇒ 182.242.192.12
$ curl ifconfig.me/ip ⇒ 182.242.192.12
$ curl ifconfig.me/host ⇒
$ curl ifconfig.me/ua ⇒ Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
$ curl ifconfig.me/port ⇒ 56688
$ curl ifconfig.me/lang ⇒ en-US,en;q=0.5
$ curl ifconfig.me/keepalive ⇒
$ curl ifconfig.me/connection ⇒ keep-alive
$ curl ifconfig.me/encoding ⇒ gzip, deflate
$ curl ifconfig.me/mime ⇒ text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
$ curl ifconfig.me/charset ⇒
$ curl ifconfig.me/via ⇒
$ curl ifconfig.me/forwarded ⇒

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
1 篇内容引用