如果运行DD-WRT路由器,并在使用状态页面将路由器的时候,你可以用一个脚本... wget的状态页面,猫的IP地址,并将其写入文件进行比较,当最新的wget IP地址与比较文件中的内容发生更改时,会发送电子邮件。
我在Linksys wrt54g路由器上运行dd-wrt,并使用以下脚本: 它从192.168.3.1开始运行路由器状态页面,在页面上使用cat(index.html)并查询wan ip地址,然后将其写入文件(gotip.txt)。
捕获的ip(gotip.txt)和当前工作ip(workingip.txt)之间进行比较。如果IP地址不同,我会收到新邮件发送的邮件,并将新的工作IP写入workingip.txt文件。
cron运行此每隔5分钟左右,我有cron的输出沉默到/ dev/null的
#!/bin/bash
getip=$(wget http://192.168.3.1/)
cat index.html | grep "wan_ipaddr" > gotip.txt
gotip=$(cat gotip.txt)
compare=$(cat workingip.txt)
if [[ "$compare" != "$gotip" ]]
then
EMAIL="[email protected]"
EMAILMESSAGE="/home/pi/ipmessage.txt"
echo "ip address is now $gotip" >> $EMAILMESSAGE
/usr/sbin/sendmail -t "$EMAIL" < $EMAILMESSAGE
rm ipmessage.txt
cp gotip.txt workingip.txt
rm index.html
else
echo "done"
rm index.html
fi