极简·不跟踪·永久免费
JSON API
- api 地址 : https://setb.cn/ip.json
- 返回JSON对象,key取自请求参数var(默认var=publicip),value是用户的IP地址
- 举例:
下面是用命令获取json对象,供参考
$ curl https://setb.cn/ip.json
{"publicip": "101.201.220.2"}
$ curl https://setb.cn/ip.json?var=me
{"me": "101.201.220.2"}
$ wget -q -O - https://setb.cn/ip
{"publicip": "101.201.220.2"}
$ wget -q -O - https://setb.cn/ip?var=me
{"me": "101.201.220.2"}
$ curl https://setb.cn/ip.json
{"publicip": "101.201.220.2"}
$ curl https://setb.cn/ip.json?var=me
{"me": "101.201.220.2"}
$ wget -q -O - https://setb.cn/ip
{"publicip": "101.201.220.2"}
$ wget -q -O - https://setb.cn/ip?var=me
{"me": "101.201.220.2"}
Javascript API
- api 地址 : https://setb.cn/ip.js
- 用法:
- ① 首先定义一个变量,比如叫 publicip
- ② 接着引入上述 API
- ③ 后续脚本如果需要公网 IP,直接引用变量 publicip 即可
- 举例:
<!-- 定义变量 -->
<script>
var publicip;
</script>
...
<!-- 引入API -->
<script src="https://setb.cn/ip.js?var=publicip"></script>
...
<!-- 可以使用了 -->
<script>
document.write("你的公网IP : ", publicip);
</script>
<script>
var publicip;
</script>
...
<!-- 引入API -->
<script src="https://setb.cn/ip.js?var=publicip"></script>
...
<!-- 可以使用了 -->
<script>
document.write("你的公网IP : ", publicip);
</script>
脚本获取公网IP
- api 地址 : https://setb.cn/ip
- 说明:用户可以用简单的命令或者脚本,直接获取本机公网IP
- 代码示例:
shell
python
go
nodejs
ruby
perl
#!/usr/bin/env bash
IP=$(curl -s https://setb.cn/ip)
echo "我的公网IP:${IP}"
IP=$(curl -s https://setb.cn/ip)
echo "我的公网IP:${IP}"
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import urllib.request
res = urllib.request.urlopen('https://setb.cn/ip')
IP = res.read().decode("utf-8").strip()
print('我的公网IP:', IP)
#-*- coding: utf-8 -*-
import urllib.request
res = urllib.request.urlopen('https://setb.cn/ip')
IP = res.read().decode("utf-8").strip()
print('我的公网IP:', IP)
///usr/bin/true; exec /usr/bin/env go run "$0" "$@"
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
response, err := http.Get("https://setb.cn/ip")
if err != nil {
// handle error
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
fmt.Print("我的公网IP: ", string(body))
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
response, err := http.Get("https://setb.cn/ip")
if err != nil {
// handle error
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
fmt.Print("我的公网IP: ", string(body))
}
#!/usr/bin/env node
const https = require('https')
https.get('https://setb.cn/ip', (res) => {
res.on('data', (chunk) => {
let IP=chunk.toString().trim();
console.log(`我的公网IP: ${IP}`);
});
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
});
const https = require('https')
https.get('https://setb.cn/ip', (res) => {
res.on('data', (chunk) => {
let IP=chunk.toString().trim();
console.log(`我的公网IP: ${IP}`);
});
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
});
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
require "open-uri"
uri = "https://setb.cn/ip"
html_response = nil
open(uri) do |http|
html_response = http.read
end
puts "我的公网IP: #{html_response}"
# -*- coding: UTF-8 -*-
require "open-uri"
uri = "https://setb.cn/ip"
html_response = nil
open(uri) do |http|
html_response = http.read
end
puts "我的公网IP: #{html_response}"
#!/usr/bin/env perl
use LWP::UserAgent;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my $useragent = new LWP::UserAgent();
my $IP = $useragent->get('https://setb.cn/ip')->content;
print '我的公网IP: '. $IP;
use LWP::UserAgent;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my $useragent = new LWP::UserAgent();
my $IP = $useragent->get('https://setb.cn/ip')->content;
print '我的公网IP: '. $IP;