HomeNAS IP变化规律
成都电信分配给个人的家用宽带IP地址定期更新,本来是用来快速发现变化后的IP地址的一个任务,解决IP地址变化后需要15分钟才能登录的问题,结果让发现了IP地址变化的规律。每隔6天,在每天中午11点20后的一个小时内更新IP地址。不知道是只针对特定账号的任务还是所有人同一时刻变更。
这里也分享一下监控脚本源码:
#!/bin/bash
getip() {
echo $(curl https://ip.tool.lu 2>;/dev/null|grep IP|awk '{print $2}'|tr -d '^M')
}
lastip=$(getip)
while :
do
sleep 5
ip=$(getip)
if [ ! -z "$ip" -a "$ip" != "${lastip}" ]
then
echo $(date) >;> result.txt
echo "ip changed from ${lastip} to ${ip}" >;> result.txt
curl -s --user 'api:XXXXXXXXXXXXXXXXX' https://api.mailgun.net/v3/codefine.site/messages -F from='Shentar admin@xxx.com' -F to=youremail@address -F subject='Home NAS IP Changed!' -F text="ip changed form ${lastip} to ${ip}"
lastip=${ip}
fi
done
具体的账号秘钥和邮箱地址均已隐去。使用ip.tool.lu识别本机的外网IP,然后监控指定间隔内两次IP地址的变化。如果发生变化,则使用MailGun服务发送邮件到指定邮箱。