Though there are probably some better solutions out there, I wrote a simple bash script to email me when my server’s IP address changes. My ISP loves to change my IP address randomly, and when I’m not home for extended periods of time, it’s a pain to not have access. This script will email me when my IP changes.
#!/bin/sh
# By Luke Hoersten <Luke.Hoersten@gmail.com>
# This will send an email on external IP changes.
EMAIL="my@email.address.com"
MESSAGE="/tmp/tmp-msg"
URL="http://wooledge.org/myip.cgi"
EXPECTED_IP="ip.address"
ACTUAL_IP=`curl "$URL" 2> /dev/null`
HOSTNAME="hostname"
if [ $EXPECTED_IP = $ACTUAL_IP ] ; then
exit 0
fi
echo "$HOSTNAME's IP has changed on" `date` > $MESSAGE
echo "Expected: '$EXPECTED_IP' -- Actual: '$ACTUAL_IP'" >> $MESSAGE
echo >> $MESSAGE
/usr/bin/mailx -s "$HOSTNAME IP Changed" $EMAIL < $MESSAGE
exit 1
- None Found