IPNotify

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
  • ryan
    Nice. But I think some sort of dynamic dns service would prove much less hassle.

    No-ip, Dyndns, etc.
  • Like I said, there are probably better solutions out there. This script was a simple 10 min copy and paste from some other scripts I'd written before so it wasn't much of a hassle.

    As far as I know, No-ip and Dyndns only support dynamic DNS with their given sub-domain names. Having both their sub-domain and my domain names point to my servers would work but in that situation, I would have to notice my domain name was not working and then ping the dyndns domain to get my new IP and redirect the A Record. With my script, it will just email me whenever the cron job runs. I'd rather just get an email =)
blog comments powered by Disqus