DynDNS alternative

Ok it’s not exactly an alternative, but finally I can find my home internet IP address in most of the times. I have a linuxbox running at home as a file server in 0-24, so I just put together a script to send me an email about the new IP address (if it has already been changed). The only thing I need to do to figure out the current IP is to check the last email from myself;).

So, my box is a debian linux, you need to install the following things:
$ sudo apt get update
$ sudo apt-get install curl ssmtp mtab

Configure ssmtp:
sudo nano /etc/ssmtp/ssmtp.conf

[email protected]
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password
FromLineOverride=YES
UseTLS=YES

(I borrowed the SSMTP setup from here: http://ozzmaker.com/2012/12/03/send-email-from-the-raspberry-pi-or-linux-command-line-with-attachments/)

Let’s see the script:

nano ip-script.sh

#!/bin/bash
curripfile=/data/currentip.txt
oldipfile=/data/oldip.txt

content="$(curl -s ifconfig.me)"
echo "$content" > $curripfile

minimumsize=10
actualsize=$(wc -c "$curripfile" | cut -f 1 -d ' ')

if [ $actualsize -ge $minimumsize ] ; then
if ! diff $curripfile $oldipfile >/dev/null ; then
# echo Different
mv -f $curripfile $oldipfile
mpack -s "IP Addres change detected" $oldipfile [email protected]
fi
fi

Finally set up the cron to run it every 10 minutes:
$ crontab -e

*/10 * * * * /data/ip-script.sh