用API更新3322.org免费二级域名的DDNS:
1、注册3322.org的免费二级域名:http://www.pubyun.com/
2、把下面的shell脚步保存为updateDDNS.sh。mydomain替换为你自己的二级域名,username:password替换为你自己在3322注册的帐号。用http://icanhazip.com获得公网IP。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ ! -e /tmp/dnsip.txt ] ; then | |
ping mydomain.f3322.org -c1 | grep PING | awk '{ print $3 }' | sed 's/[()]//g' > /tmp/dnsip.txt | |
fi | |
mydnsip=$(head -1 /tmp/dnsip.txt) | |
curl -s http://icanhazip.com > /tmp/ip.txt | |
myip=$(head -1 /tmp/ip.txt) | |
echo "current IP:"$myip | |
if [ "$mydnsip" = "$myip" ] ; then | |
echo 'IP is not change' | |
else | |
http_code=`curl -o /dev/null -s -w %{http_code} --basic -u username:password "http://members.3322.net/dyndns/update?myip=$myip&hostname=mydomain.f3322.org"` | |
if [ $http_code -eq 200 ] ; then | |
echo 'update DDNS success' | |
echo $myip > /tmp/dnsip.txt | |
else | |
echo 'update DDNS fail:$http_code' | |
fi | |
fi |
3、在cron里添加每N分钟执行updateDDNS.sh。

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。