想在项目中实现通过访问者IP
得到该IP
对应的地区或城市,有什么比较好的办法吗?
之前没有经验,想到的两种可能实现:
- 通过网上下载的数据导入数据库,与
IP
比对进行分析 - 通过接口或者直接抓取现有的网页取得结果
麻烦大家分享一下,谢谢
想在项目中实现通过访问者IP
得到该IP
对应的地区或城市,有什么比较好的办法吗?
之前没有经验,想到的两种可能实现:
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 ⇒
淘宝的 API: http://ip.taobao.com/instructions.php
或者自己用 GeoIP(如果用量较大): http://php.net/manual/en/book.geoip.php