Here's a Linux shell script to scrape the current IP from a Linksys router's status page once per minute and log any changes.
Code:
#!/bin/sh
# Reads internet IP from Linksys router, reports changes
clear
b=0
message='- logging start'
if [ "$2" != '' ]; then
router_username=$2
else
router_username="admin"
fi
if [ "$3" != '' ]; then
output_filename=$3
else
output_filename="~/ip_history.txt"
fi
if [ "$1" != '' ]; then
while [ $b = 0 ]
do IPADR2=$IPADR;
IPADR=$(wget -q -O - http://$router_username:$1@192.168.1.1/Status_Router.asp | sed -n '/ipaddr/ {n;p;}' | sed -e 's/.*<B>//; s/<\/B>.*//')
if [ "$IPADR" != "$IPADR2" ]; then
dttim=$(date)
echo $dttim $IPADR $message
echo $dttim $IPADR $message >> $output_filename
message=''
fi
sleep 60s
done
else
echo "Usage: ip_history [router_password] {router_username} {output /path/filename}"
echo "Router username defaults to admin"
echo "Output defaults to ~/ip_history.txt"
fi
Copy this code into a text editor, save it wherever you want, name it ip_history, and set it executable.
For some Linksys routers, the status page is Status_Router.htm (or something similar) instead of .asp.
If your router doesn't offer a status page, you can modify this script to pull the IP from whatismyip.com. Substitute this line to set the IPADR variable:
Code:
IPADR=$(wget www.whatismyip.com/automation/n09230945.asp -O - -q)
...and change
sleep 60s to
sleep 300s (or a higher value) to avoid hitting whatismyip.com's automation page more frequently than five minutes apart.
I have this script set to run automatically when I boot, so it doesn't have its own window; but if you run it manually, it will log IP changes to the terminal window as well as the log file.