Posted on 2006-07-17 18:34
acooly 阅读(6750)
评论(8) 编辑 收藏 所属分类:
Linux/Unix
家里的电脑用的是ADSL上网,没有固定的域名,为了从公司方便的访问家里的电脑,我在希网(
www.3322.org)申请了一个动态域名。但后来我家里操作系统改为linux并是用的路由器上网,希网提供的linux客户端不能更新路由器的外网IP地址,没办法,我只有自己写个shell取得路由器的公网IP,然后用希网提供的GET方式接口更新路由器的公网IP了。
#!/bin/sh
# ip file from Router WEB Manager
#curdate=date +"%Y-%m-%d %H:%M:%S"
echo `date +"%Y-%m-%d %H:%M:%S"` >>/g/linux_tools/bin/dydns.log
wget -q -C off -O remoteip http://admin:admin@192.168.1.1/userRpm/StatusRpm.htm
iptmp=`sed -n '/IP/p' remoteip |sed '1d'|sed 's/<[a-z,\/]*>//g'|sed 's/^IP.\{4\}//g'`
if [ -z "$iptmp" ]; then
echo "no connecting internet." >>/g/linux_tools/bin/dydns.log
else
rm -f ipupdate
wget -q -C off -O ipupdate "http://cqpower:cqpower.net@members.3322.org/dyndns/update?&hostname=zpu.3322.org&myip=$iptmp"
ret=`awk '{if($1~/good/ || $1~/nochg/) print $1}' ipupdate|sed -n '1p'`
if [ "$ret"="good" -o "$ret"="nochg" ]; then
echo "update internet ip success:$iptmp" >>/g/linux_tools/bin/dydns.log
else
echo "update internet ip failure!" >>/g/linux_tools/bin/dydns.log
fi
fi
echo "" >> dydns.log