> nslookup myip.opendns.com. resolver1.opendns.com
...
Name: myip.opendns.com
Address: 101.69.24.2
OR
> nslookup myip.opendns.com resolver1.opendns.com | grep 'myip.opendns.com' -A 1 | grep 'Address' | awk '{print $2}'
125.120.213.100
101.69.24.2
DNSPOD API DOC: https://www.dnspod.cn/docs/records.html#dns
Suppose:
- your domain: mydomain.com
- your dnspod login token: 94888,d2ea401be61b814fffffffffffffffff
- your ddns sub domain: myhome (so you can use
myhome.mydomain.comto visit)
DNSPOD LOGIN TOKEN (id and token splited by ','): 94888,d2ea401be61b814fffffffffffffffff
> curl -X POST https://dnsapi.cn/Record.List -d 'login_token=94888,d2ea401be61b814fffffffffffffffff&format=json&domain=mydomain.com'
{
"domain": {
"dnspod_ns": [
"f1g1ns1.dnspod.net",
"f1g1ns2.dnspod.net"
],
"ext_status": "",
"grade": "DP_Free",
"id": "24788888",
"min_ttl": 600,
"name": "mydomain.com",
"owner": "my-dnspod-account@gmail.com",
"punycode": "mydomain.com",
"status": "enable",
"ttl": 600
},
"info": {
"record_total": "6",
"records_num": "6",
"sub_domains": "6"
},
"records": [
...
{
"enabled": "1",
"id": "420999999",
"line": "\u9ed8\u8ba4",
"line_id": "0",
"monitor_status": "",
"mx": "0",
"name": "myhome",
"remark": "",
"status": "enabled",
"ttl": "600",
"type": "A",
"updated_on": "2019-04-26 10:31:00",
"use_aqb": "no",
"value": "101.69.24.1",
"weight": null
}
],
"status": {
"code": "1",
"created_at": "2019-04-26 10:46:52",
"message": "Action completed successful"
}
}
> curl -X POST https://dnsapi.cn/Record.Ddns -d 'login_token=94888,d2ea401be61b814fffffffffffffffff&format=json&domain=mydomain.com&record_id=420999999&record_line_id=0&sub_domain=myhome&value=101.69.24.2'
{"status":{"code":"1","message":"Action completed successful","created_at":"2019-04-26 10:54:26"},"record":{"id":420999999,"name":"myhome","value":"101.69.24.2"}}
NOTE: keep value empty will use your remote ip address as default value. In this case you can use nslookup to reduce the API's called time.
之前那篇是解释动态域名解析的原理, 这里提供一个最终的DDNS Shell脚本:
首先提供基本信息:
完整脚本: