xixitalk's snippet

Post Longer Than 140 Characters Tweets

May 29, 2013 - Comments

用API更新3322.org免费二级域名的DDNS

用API更新3322.org免费二级域名的DDNS:
1、注册3322.org的免费二级域名:http://www.pubyun.com/
2、把下面的shell脚步保存为updateDDNS.sh。mydomain替换为你自己的二级域名,username:password替换为你自己在3322注册的帐号。用http://icanhazip.com获得公网IP。

#!/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
view raw updateDDNS.sh hosted with ❤ by GitHub

3、在cron里添加每N分钟执行updateDDNS.sh。


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

Tags: DDNS

stunnel原理 用iptables将8222端口转向22(SSH)