IP.SB - 在线 IPv4 / IPv6 信息查询
1、IP.SB 的由来
IP.SB 前身是 IP.GS ,一个专门用于查询本地出口 IP 的网站,初衷是为了让用户更方便地知道自己的本地出口 IP,使用的数据库是 IPIP.NET 提供的商业版
随着访问量增加,并且全世界 IPv6 渐渐普及,我们发现仅仅使用 IPIP.NET 的数据库已经无法满足需求,比如他们没有提供 IPv6 数据库,而国外的 Maxmind 的 IPv4 数据库准确性又没有 IPIP.NET 高,所以综合对比之后,我们决定重新改版 IP.GS,加入 Maxmind 的 IPv6 和 ISP 数据库,当然也为了统一域名,所以 IP.GS 改成了目前的 IP.SB
2、IP.SB 使用的 IP 数据库
IPv4 物理位置数据库是 IPIP.NET 提供的商业版,介绍和购买链接请摸这儿
IPv6 和 ISP 数据库是 MaxMind 提供的商业版,介绍和购买链接请摸这儿
3、IP.SB 基本功能介绍
3.1 查看本地出口 IP 地址
直接访问 ip.sb 即可查看当前本地的 IP 出口地址,如果本地有 IPv6 ,那么我们也会同时检测出 IPv6 地址,如果没有则只有 IPv4 地址,目前我们检测的原理如下:
ip.sb
同时解析了 IPv4 和 IPv6 地址,方便用户访问ipv4.ip.sb
只解析了 IPv4 地址,用途是检测用户的 IPv4,如果有,则提示Supported
ipv6.ip.sb
只解析了 IPv6 地址,用途是检测用户的 IPv6,如果有,则提示Supported
,如果没有或者当前 IPv6 连接失败,则提示Not Supported
3.2 查询 IP 地址物理位置
假设你想查询的 IPv4 是 192.0.2.2
,IPv6 是 2001:db8::2
那么直接访问如下地址即可查询您的 IP 物理位置信息
也可以在 ip.sb 右上角搜索,直接输入 IP 地址即可
3.3 查询 IP 和 ASN 的 whois 信息
假设你想查询的 IPv4 是 192.0.2.2
,IPv6 是 2001:db8::2
,ASN 是 AS9312
那么直接访问如下地址即可查询相关公开的 whois 信息
https://ip.sb/whois/2001:db8::2
当然你也可以在 https://ip.sb/whois/ 页面输入查询,注意的是,并不是所有的 IP 地址或 ASN 都会有对应的 whois 信息
3.4 查询 IP 基本知识
目前我们收集并制作了如下页面
IPv4 和 IPv6 的 CIDR https://ip.sb/cidr/.
IANA 的 IPv4 和 IPv6 分配 https://ip.sb/iana-ip/
IANA 的 ASN 分配 https://ip.sb/iana-asn/
所有的国别域名分配 https://ip.sb/cctlds/
未来会加入更多的 IP 和 域名知识页面
3.5 其他小工具
本地浏览器环境监测 (主要用途是查看本地代理是否正常) https://ip.sb/azenv/
IP 地址转换 PTR 记录 https://ip.sb/ip2ptr/
未来也会加入更多的小工具
4、简单 API 使用
4.1 curl 方式
首先,确保您的系统安装了 curl ,查询本地 IP 出口地址命令如下
当然如果你使用 curl 那么你也可以通过 curl ip.sb
命令来查看当前的 IP 地址,具体用法如下
默认情况下
curl ip.sb
只想查询 IPv4 的时候
curl -4 ip.sb
或
curl ipv4.ip.sb
只想查询 IPv6 的时候
curl -6 ip.sb
或
curl ipv6.ip.sb
4.2 文本方式或者 IP
直接访问 https://api.ip.sb/ip
即可获得当前 IP 地址,访问 https://api-ipv4.ip.sb/ip
获取 IPv4 地址,访问 https://api-ipv6.ip.sb/ip
获取 IPv6 地址,可配合任何程序使用
4.3 JSON 方式获取 IP
直接访问 https://api.ip.sb/jsonip
或 https://api.ip.sb/jsonip?callback=getip
后获取 JSON 格式的输出
更多使用方法请参考 http://ip.sb/api/
目前免费 API 暂无限制,但是请勿滥用,如果需要商业使用请自行搭建或联系我们
IP.SB Free API
This service offers a REST API allowing to get a visitor IP address and to query location information from any IP address. It outputs JSON-encoded IP geolocation data, and supports both Cross-origin resource sharing (CORS) and JSONP.
IP (Get IP address in plain text format):
Returns the visitor IP address (IPv4 or IPv6) in plain text, useful for shell scripts or to find the external Internet routable address.
- Example (Plain text): https://api.ip.sb/ip
- Example (curl):
curl ip.sb
Alternatively, for more granularity when querying from a dual-stack environments, the following endpoints are available:
- Example (Plain text): https://api.ip.sb/ip (Listen on both IPv4 and IPv6) or
curl ip.sb
- Example (Plain text): https://api-ipv4.ip.sb/ip (Listen on IPv4 only) or
curl -4 ip.sb
orcurl ipv4.ip.sb
- Example (Plain text): https://api-ipv6.ip.sb/ip (Listen on IPv6 only) or
curl -6 ip.sb
orcurl ipv6.ip.sb
Usage example (Shell script):
#!/bin/sh
ip=$(curl -s https://api.ip.sb/ip)
echo "My IP address is: $ip"
Output example:
IPv4 address:
192.0.2.2
IPv6 address:
2001:db8::2
JSON IP (Get IP address in JSON format):
Returns the visitor IP address (IPv4 or IPv6) in a JSON object.
- Example (JSON): https://api.ip.sb/jsonip
- Example (JSONP): https://api.ip.sb/jsonip?callback=getip
Usage example:
<script type="application/javascript">
function getip(json){
document.write("My IP address is: ", json.ip);
}
</script>
<script type="application/javascript" src="https://api.ip.sb/jsonip?callback=getip"></script>
Usage example (jQuery):
<script type="application/javascript">
$(document).ready(function() {
$.getJSON("https://api.ip.sb/jsonip?callback=?",
function(json) {
document.write("My IP address is: ", json.ip);
}
);
});
</script>
GeoIP (Get IP address location in JSON format):
Calling the API endpoint without any parameter will return location information for the visitor IP address:
- Example (JSON): https://api.ip.sb/geoip
- Example (JSONP): https://api.ip.sb/geoip?callback=getgeoip
Appending an IP address as parameter will return location information for this IP address:
- Example (JSON): https://api.ip.sb/geoip/185.222.222.222
- Example (JSONP): https://api.ip.sb/geoip/185.222.222.222?callback=getgeoip
- Example (JSON): https://api.ip.sb/geoip/2a09::
- Example (JSONP): https://api.ip.sb/geoip/2a09::?callback=getgeoip
Usage example:
<script type="application/javascript">
function getgeoip(json){
document.write("Geolocation information for IP address: ", json.ip);
document.write("Country: ", json.country);
document.write("Latitude: ", json.latitude);
document.write("Longitude: ", json.longitude);
}
</script>
<script type="application/javascript" src="https://api.ip.sb/geoip?callback=getgeoip"></script>
Usage example (jQuery):
<script type="application/javascript">
$(document).ready(function() {
$.getJSON("https://api.ip.sb/geoip?callback=?",
function(json) {
document.write("Geolocation information for IP address: ", json.ip);
document.write("Country: ", json.country);
document.write("Latitude: ", json.latitude);
document.write("Longitude: ", json.longitude);
}
);
});
</script>
JSON Output Schema
The output is a JSON object containing the following elements:
Please note that the IP location database may not contain all information about a given IP. In this case, only the available data is displayed.
- ip (Visitor IP address, or IP address specified as parameter)
- country_code (Two-letter ISO 3166-1 alpha-2 country code)
- country (Name of the country)
- region_code (Two-letter ISO-3166-2 state / region code for US and Canada, FIPS 10-4 region codes otherwise)
- region (Name of the region)
- city (Name of the city)
- postal_code (Postal code / Zip code)
- continent_code (Two-letter continent code)
- latitude (Latitude)
- longitude (Longitude)
- organization (ASN + ISP name)
- timezone (Time Zone)
Output example:
The following example use xTom server IP: city, region, and postal code information is not available and thus not present in the output JSON object:
{
"ip": "185.255.55.55",
"country_code": "NL",
"country": "Netherlands",
"continent_code": "EU",
"latitude": 52.3824,
"longitude": 4.8995,
"asn": "3214",
"organization": "xTom Limited",
"timezone": "Europe/Amsterdam",
}
Errors
Client Errors
When incorrect user input is entered, the server returns an HTTP 400 Error (Bad Request), along with a JSON-encoded error message.
HTTP Error | Code | Message |
---|---|---|
400 | 401 | Input string is not a valid IP address |
Acknowledgment
This service includes GeoLite data created by MaxMind, available from maxmind.com.
Source Code modified from Telize