文档章节

JavaScript 获得客户端IP

o
 osc_z1hvg4cu
发布于 2018/04/24 11:12
字数 1153
阅读 29
收藏 0

钉钉、微博极速扩容黑科技,点击观看阿里云弹性计算年度发布会!>>>

Below are all the free active IP lookup services I could find and the information they return. If you know of any more, then please add a comment and I'll update this answer.


DB-IP

Try it: http://api.db-ip.com/addrinfo?api_key=<your api key>&addr=<ip address>

Returns:

{
  "address": "116.12.250.1", "country": "SG", "stateprov": "Central Singapore", "city": "Singapore" }

Limitations:

  • 2,500 requests per day
  • Doesn't support JSONP callbacks
  • Requires IP address parameter
  • Requires email address to get your API key
  • No SSL (https) with free plan

Geobytes

Try it: http://gd.geobytes.com/GetCityDetails

$.getJSON('http://gd.geobytes.com/GetCityDetails?callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "geobytesforwarderfor": "", "geobytesremoteip": "116.12.250.1", "geobytesipaddress": "116.12.250.1", "geobytescertainty": "99", "geobytesinternet": "SA", "geobytescountry": "Saudi Arabia", "geobytesregionlocationcode": "SASH", "geobytesregion": "Ash Sharqiyah", "geobytescode": "SH", "geobyteslocationcode": "SASHJUBA", "geobytescity": "Jubail", "geobytescityid": "13793", "geobytesfqcn": "Jubail, SH, Saudi Arabia", "geobyteslatitude": "27.004999", "geobyteslongitude": "49.660999", "geobytescapital": "Riyadh ", "geobytestimezone": "+03:00", "geobytesnationalitysingular": "Saudi Arabian ", "geobytespopulation": "22757092", "geobytesnationalityplural": "Saudis", "geobytesmapreference": "Middle East ", "geobytescurrency": "Saudi Riyal", "geobytescurrencycode": "SAR", "geobytestitle": "Saudi Arabia" }

Limitations:

  • 16,384 requests per hour
  • No SSL (https) with free plan
  • Can return the wrong location (I'm in Singapore, not Saudi Arabia)

GeoIPLookup.io

Try it: https://json.geoiplookup.io/api

$.getJSON('https://json.geoiplookup.io/api?callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
    "ip": "116.12.250.1", "isp": "SGPOST", "org": "Singapore Post Ltd", "hostname": "116.12.250.1", "longitude": "103.807", "latitude": "1.29209", "postal_code": "", "city": "Singapore", "country_code": "SG", "country_name": "Singapore", "continent_code": "AS", "region": "Central Singapore", "district": "", "timezone_name": "Asia\/Singapore", "connection_type": "", "asn": "AS3758 SingNet", "currency_code": "SGD", "currency_name": "Singapore Dollar", "success": true }

Limitations:

  • Unknown

geoPlugin

Try it: http://www.geoplugin.net/json.gp

$.getJSON('http://www.geoplugin.net/json.gp?jsoncallback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "geoplugin_request": "116.12.250.1", "geoplugin_status": 200, "geoplugin_credit": "Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\\'http://www.maxmind.com\\'>http://www.maxmind.com</a>.", "geoplugin_city": "Singapore", "geoplugin_region": "Singapore (general)", "geoplugin_areaCode": "0", "geoplugin_dmaCode": "0", "geoplugin_countryCode": "SG", "geoplugin_countryName": "Singapore", "geoplugin_continentCode": "AS", "geoplugin_latitude": "1.2931", "geoplugin_longitude": "103.855797", "geoplugin_regionCode": "00", "geoplugin_regionName": "Singapore (general)", "geoplugin_currencyCode": "SGD", "geoplugin_currencySymbol": "&#36;", "geoplugin_currencySymbol_UTF8": "$", "geoplugin_currencyConverter": 1.4239 }

Limitations:

  • 120 requests per minute
  • No SSL (https) with free plan

Hacker Target

Try it: https://api.hackertarget.com/geoip/?q=<ip address>

Returns:

IP Address: 116.12.250.1
Country: SG
State: N/A
City: Singapore
Latitude: 1.293100
Longitude: 103.855797

Limitations:

  • 50 requests per day
  • Doesn't support JSONP callbacks
  • Requires IP address parameter
  • Returns plain text

ipapi.co

Try it: https://ipapi.co/json/

$.getJSON('https://ipapi.co/json/', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip": "116.12.250.1", "city": "Singapore", "region": "Central Singapore Community Development Council", "country": "SG", "country_name": "Singapore", "postal": null, "latitude": 1.2855, "longitude": 103.8565, "timezone": "Asia/Singapore" }

Limitations:

  • 1,000 requests per day
  • Requires SSL (https)

IP-API.com

Try it: http://ip-api.com/json

$.getJSON('http://ip-api.com/json?callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "as": "AS3758 SingNet", "city": "Singapore", "country": "Singapore", "countryCode": "SG", "isp": "SingNet Pte Ltd", "lat": 1.2931, "lon": 103.8558, "org": "Singapore Telecommunications", "query": "116.12.250.1", "region": "01", "regionName": "Central Singapore Community Development Council", "status": "success", "timezone": "Asia/Singapore", "zip": "" }

Limitations:

  • 150 requests per minute
  • No SSL (https) with free plan

Ipdata.co

Try it: https://api.ipdata.co

$.getJSON('https://api.ipdata.co', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip": "116.12.250.1", "city": "Singapore", "region": "Central Singapore Community Development Council", "region_code": "01", "country_name": "Singapore", "country_code": "SG", "continent_name": "Asia", "continent_code": "AS", "latitude": 1.2854999999999999, "longitude": 103.8565, "asn": "AS3758", "organisation": "SingNet", "postal": "", "currency": "SGD", "currency_symbol": "$", "calling_code": "65", "flag": "https://ipdata.co/flags/sg.png", "emoji_flag": "🇸🇬", "time_zone": "Asia/Singapore", "is_eu": false, "suspicious_factors": { "is_tor": false } }

Limitations:

  • 1,500 requests per day
  • Requires SSL (https)

IP Find

Try it: https://ipfind.co/me?auth=<your api key>

$.getJSON('https://ipfind.co/me?auth=<your_api_key>', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip_address": "116.12.250.1", "country": "Singapore", "country_code": "SG", "continent": "Asia", "continent_code": "AS", "city": "Singapore", "county": null, "region": "Central Singapore", "region_code": "01", "timezone": "Asia/Singapore", "owner": null, "longitude": 103.8565, "latitude": 1.2855, "currency": "SGD", "languages": [ "cmn", "en-SG", "ms-SG", "ta-SG", "zh-SG" ] }

Limitations:

  • 300 requests per day
  • Requires registration to get your API key

ipify

Try it: https://api.ipify.org/?format=json

$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip": "116.12.250.1" }

Limitations:

  • None

IPInfoDB

Try it: https://api.ipinfodb.com/v3/ip-city/?key=<your api key>&format=json

$.getJSON('https://api.ipinfodb.com/v3/ip-city/?key=<your_api_key>&format=json&callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "statusCode": "OK", "statusMessage": "", "ipAddress": "116.12.250.1", "countryCode": "SG", "countryName": "Singapore", "regionName": "Singapore", "cityName": "Singapore", "zipCode": "048941", "latitude": "1.28967", "longitude": "103.85", "timeZone": "+08:00" }

Limitations:

  • Two requests per second
  • Requires registration to get your API key

ipinfo.io

Try it: https://ipinfo.io/json

$.getJSON('https://ipinfo.io/json', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip": "116.12.250.1", "hostname": "No Hostname", "city": "Singapore", "region": "Central Singapore Community Development Council", "country": "SG", "loc": "1.2931,103.8558", "org": "AS3758 SingNet" }

Limitations:

  • 1,000 requests per day

ipstack (formerly freegeoip.net)

Try it: http://api.ipstack.com/<ip address>?access_key=<your api key>

$.getJSON('http://api.ipstack.com/<ip_address>?access_key=<your_api_key>', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
    "ip": "116.12.250.1", "type": "ipv4", "continent_code": "AS", "continent_name": "Asia", "country_code": "SG", "country_name": "Singapore", "region_code": "01", "region_name": "Central Singapore Community Development Council", "city": "Singapore", "zip": null, "latitude": 1.2931, "longitude": 103.8558, "location": { "geoname_id": 1880252, "capital": "Singapore", "languages": [{ "code": "en", "name": "English", "native": "English" }, { "code": "ms", "name": "Malay", "native": "Bahasa Melayu" }, { "code": "ta", "name": "Tamil", "native": "\u0ba4\u0bae\u0bbf\u0bb4\u0bcd" }, { "code": "zh", "name": "Chinese", "native": "\u4e2d\u6587" }], "country_flag": "http:\/\/assets.ipstack.com\/flags\/sg.svg", "country_flag_emoji": "\ud83c\uddf8\ud83c\uddec", "country_flag_emoji_unicode": "U+1F1F8 U+1F1EC", "calling_code": "65", "is_eu": false } }

Limitations:

  • 10,000 requests per month
  • Requires IP address parameter
  • Requires registration to get your API key
  • No SSL (https) with free plan

jsonip.com

Try it: https://jsonip.com

$.getJSON('https://jsonip.com/?callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip": "116.12.250.1", "about": "/about", "Pro!": "http://getjsonip.com", "reject-fascism": "Liberal America will prevail" }

Limitations:

  • Response includes upsell and politics

JSON Test

Try it: http://ip.jsontest.com/

$.getJSON('http://ip.jsontest.com/?callback=?', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "ip": "116.12.250.1" }

Limitations:

  • No SSL (https)
  • Goes down a lot (over quota), so I wouldn't use it for production
  • Returns IPv6 address if you have one, which may not be what you want

Nekudo

Try it: https://geoip.nekudo.com/api/<ip address>

$.getJSON('https://geoip.nekudo.com/api/<ip_address>', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "city": "Singapore", "country": { "name": "Singapore", "code": "SG" }, "location": { "accuracy_radius": 50, "latitude": 1.2855, "longitude": 103.8565, "time_zone": "Asia/Singapore" }, "ip": "116.12.250.1" }

Limitations:

  • Requires IP address parameter
  • Blocked by ad blockers using EasyPrivacy list

Stupid Web Tools

Try it: http://www.stupidwebtools.com/api/my_ip.json

$.getJSON('http://www.stupidwebtools.com/api/my_ip.json', function(data) { console.log(JSON.stringify(data, null, 2)); });

Returns:

{
  "my_ip": { "ip": "116.12.250.1", "others": [] } }

Limitations:

  • No SSL (https)

Keep in mind that since these are all free services, your mileage may vary in terms of exceeding quota and uptime, and who knows when/if they will be taken offline down the road (exhibit A: Telize). Most of these services also offer a paid tier in case you want more features like SSL support.

Also, as skobaljic noted in the comments below, the request quotas are mostly academic since this is happening client-side and most end users will never exceed the quota.

o
粉丝 0
博文 500
码字总数 0
作品 0
私信 提问
加载中
请先登录后再评论。
Web移动应用调试工具——Weinre

由于前面介绍的方式不太给力,于是找到了资深的学长问了问,他告诉我有个叫weinre的插件很不错,在进一步了解,发现了这篇文章。 weinre官网:http://people.apache.org/~pmuellr/weinre/do...

Megan_zhou
2013/06/14
523
0
weinre配置

如今人们也越来越习惯在手机上浏览网页,而在手机上这些针对桌面浏览器设计的网页经常惨不忍睹。Web应用开发者需要针对手机进行界面的重新设计,但是手机上并没有称心如意的调试工具(如Fir...

华哥_
2013/08/15
50
0
网站如何定位用户省份?

我的网站有一个页面想根据访问用户省份不同展示不同内容, 所以想知道怎么定位用户省份? 了解的方案大概有: 1. 通过前端地理位置API获得经纬度, 再用百度地图API查省份; 2. 通过前端第三方jav...

sanzado
2017/05/17
290
7
JS获取IP、MAC和主机名的几种方法

今天在搞JS(javascript)获取客户端IP的小程序,上网搜了下,好多在现在的系统和浏览器中的都无效,很无奈,在Chrome、FireFox中很少搞到直接利用ActiveX获取IP等的JS脚本。下面的代码是我在...

Carl_
2014/09/05
921
0
关于websockets加密通讯!

在阿里云盾申请的ssl证书,用poco库做的服务端 ,绑定了一个域名,在浏览器用域名访问一切正常,安全的https,用IP访问 提示IP和证书域名不一致 提示不安全 但是添加例外 还是可以正常访问,现在...

我想挖颗树
2017/07/07
242
2

没有更多内容

加载失败,请刷新页面

加载更多

263. Ugly Number

题目: 263. Ugly Number 题目地址:https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers......

JiaMing
12分钟前
34
0
HCIA_ARP01

ARP(地址解析协议) eNSP 常用路由器:AR2220 常用交换机:S5700、S3700 常用终端:PC、MCS(主播服务器) 设备连线:Copper(以太网用到的双绞线)、Serial(串口线,2SA接口)、Auto(自动连...

创业789
15分钟前
13
0
如何在Rails 4中使用问题 - How to use concerns in Rails 4

问题: The default Rails 4 project generator now creates the directory "concerns" under controllers and models. 默认的Rails 4项目生成器现在在控制器和模型下创建目录“Concer”。 ......

fyin1314
19分钟前
19
0
【LeetCode】 57 括号生成

题目: 解题思路: https://leetcode-cn.com/problems/generate-parentheses/solution/hui-su-suan-fa-by-liweiwei1419/ 代码: import java.util.ArrayList;import java.util.List;publ......

JaneRoad
昨天
8
0
度小满上线“推有钱”贷款推广平台,合伙人直推佣金为贷款金额的2.5%

来源 | 镭射财经 作者 | 黄老邪 2020年,蓬勃发展的消金行业受到新冠肺炎疫情的冲击,用户增长放缓、逾期率上升成为共性问题。但疫情或许只是导火索,对于消金行业来说,用户增长红利的消退,...

镭射财经
昨天
13
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部