开发者社区> 问答> 正文

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


想在项目中实现通过访问者IP得到该IP对应的地区或城市,有什么比较好的办法吗?
之前没有经验,想到的两种可能实现:

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

麻烦大家分享一下,谢谢

展开
收起
出走的小白 2014-09-22 11:16:02 6955 0
5 条回答
写回答
取消 提交回答
  • LT是个伪程序员
    现在很多web服务,其中有包括查询IP的
    2014-09-22 13:34:53
    赞同 展开评论 打赏
  • Re如何通过IP取得用户的城市或地区
    有QQ,新浪,淘宝,等很多提供查IP的接口
    2014-09-22 12:24:23
    赞同 展开评论 打赏
  • Re如何通过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 ⇒


    2014-09-22 11:53:17
    赞同 展开评论 打赏
  • 我感觉都不是特别准
    2014-09-22 11:51:16
    赞同 展开评论 打赏
  • Re如何通过IP取得用户的城市或地区
    淘宝的 API: http://ip.taobao.com/instructions.php
    或者自己用 GeoIP(如果用量较大): http://php.net/manual/en/book.geoip.php
    2014-09-22 11:18:58
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
零售通产品分享数字化、连接、数据 立即下载
零售通产品分享 数字化、连接、数据 立即下载
与阿里云IoT一起共享智能城市万亿商机 立即下载