Think before you speak, read before you think.

自动更新花生壳的ip

by

in

参考:

http://open.oray.com/wiki/doku.php?id=文档:花生壳:http协议说明

只能使用GET方式提交信息,这里使用curl,需提前安装好curl。
加一个判断,如果当前dns中的ip和检测的ip不一致时,就自动提交;一致则退出。

#!/bin/bash
orayuser=your oray name
oraypass=your oray passoword
oraydomain=your domain
realip=`curl http://ddns.oray.com/checkip | cut -d' ' -f 6 | cut -d'<' -f 1`
theurl="http://$orayuser:[email protected]/ph/update?hostname=$oraydomain&myip=$realip"
currentip=`nslookup $oraydomain | tail -2 | head -1 | cut -d' ' -f 2`
if [ "$realip" = "$currentip" ]; then
 exit 0
else
 curl "$theurl"
fi

在crontab中加入以下内容,每十五分钟检测一次

*/15 * * * * /bin/bash /root/pushiporay.sh

–添加于2013年3月3日开始–

后来申请了noip.com的二级域名,才发现花生壳和人家的api是如此的像。同理可更新noip里的记录

#!/bin/bash
noipuser=your noip username
noippass=your noip password
noipdomain=your noip domain
realip=`curl http://ddns.oray.com/checkip | cut -d' ' -f 6 | cut -d'<' -f 1`
noipurl="http://$noipuser:[email protected]/nic/update?hostname=$noipdomain&myip=$realip"
noipcurrentip=`nslookup $noipdomain | tail -2 | head -1 | cut -d' ' -f 2`
if [ "$realip" = "$noipcurrentip" ]; then
 echo "no need to update"
 exit 0
else
 curl "$noipurl"
fi

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *