IpTeller
From XpertDNS
Just create this script anywhere you would like to run it from and execute it with a cron how often you'd like. You will need to create a directory for the script to store it's temp files.
mkdir -p /var/run/ipTeller/
[edit]
Condensed Version
#!/bin/bash
# Config
IPFILE='/var/run/ipTeller/ipTeller_ipaddress'
MAILFILE='/var/run/ipTeller/ipTeller_mailtext'
DOMAIN='' # DynDNS domain name
UNAME='' # You XpertDNS username
PASSWORD='' # Your XpertDNS password hash https://www.xpertdns.com/md5form.php
DYNID='' # This is available while editing the A record within XpertDNS
EMAIL=$UNAME # Change this to send mail to an address other than your username
ip=`curl -s http://www.xpertdns.com/myip.php` # IP address source
# Scrtip Start
if [ ! -f "$IPFILE" ]; then
echo "creating $IPFILE"
echo first_time_usage > $IPFILE
fi
if [ ! -f "$MAILFILE" ]; then
echo "creating $MAILFILE"
echo first_time_usage > $MAILFILE
fi
lastip=`cat $IPFILE`
echo "last ip saved is: $lastip"
echo "current ip address is: $ip"
if [ $ip != $lastip ]; then
date=`date +%D\ %r`
echo $ip > $IPFILE
echo "$DOMAIN's IP address is now $ip as of $date" > $MAILFILE
echo "updating dyndns"
curl -s "https://www.xpertdns.com/dyndns.php?dynid=$DYNID&ip=$ip&uname=$UNAME&password=$PASSWORD"
echo ""
echo "IP changed so sending message..."
mail -s "IP address changed." $EMAIL < $MAILFILE
echo "logging the IP change to /var/log/ipTeller_ipchange.log"
echo "$date -- IP CHANGED TO: $ip" >> /var/log/ipTeller_ipchange.log
else
exit 0;
fi
exit;
# Script End
[edit]
Regular Version
#!/bin/bash
#
# Original version: fargo@fargonet.org
# http://openskills.info/view/boxdetail.php?IDbox=304&boxtype=scripts#
#
# This script is intended to send the updated internet IP address to an email recpient (or more
# than one). It can be usefull if you have an Adsl or Cable connection with a dynamic IP address. Whenever
# your ISP changes you internet IP address, you will be notified with an email.
# So you will always know where to point your DNS, ssh or whatever...
#
#
# Modified and Cleaned up by Daevid Vincent [daevid@daevid.com]
#
# I setup up an /etc/mail/aliases to point to my cellphone's SMS gateway
# this works because even though my server changed IPs, it's still on the internet and can happily send mail
# then i get an instant SMS text message to my cell phone. works like a charm.
#
# Further Modified and Cleaned up by Michael Donnarumma [mike@xpertdns.com]
#
# I made changes to have script update dyndns on xpertdns.com
#
# /etc/crontab entry:
# */15 * * * * root /usr/local/bin/ipTeller.sh > /dev/null
#
#################################### BEGININNING OF THE SCRIPT #############################################
# Creates two files named "$IPFILE" and "mailtext" containing something the first time you execute the script,
# or recreates the files should they be missing.
IPFILE='/var/run/ipTeller/ipTeller_ipaddress'
MAILFILE='/var/run/ipTeller/ipTeller_mailtext'
DOMAIN='' # DynDNS domain name
UNAME='' # You XpertDNS username
PASSWORD='' # Your XpertDNS password https://www.xpertdns.com/md5form.php
DYNID='' # This is available while editing the A record within XpertDNS
EMAIL=$UNAME # Change this to send mail to an address other than your username
if [ ! -f "$IPFILE" ]; then
echo "creating $IPFILE"
echo first_time_usage > $IPFILE
fi
if [ ! -f "$MAILFILE" ]; then
echo "creating $MAILFILE"
echo first_time_usage > $MAILFILE
fi
# Gets last known IP address from the file "$IPFILE"
lastip=`cat $IPFILE`
echo "last ip saved is: $lastip"
# Gets current IP address
# This points to ppp0, Change this accordingly to your inet configuration.
# I used grep and awk, but they could not work correctly on some systems other than RedHat 7.2.
# You could skip the usage of awk and would probably get something like this:
# "inet addr:xxx.xxx.xxx.xxx Bcast:xxx.xxx.xxx.xxx Mask:xxx.xxx.xxx.xxx" (with your real config)
#ip=`ifconfig eth0 | grep inet| awk '{ print $2 }'| awk -F : '{ print $2 }'`
#ip=`host xpertdns.selfip.com | awk '{ print $3 }'`
#ip=`curl -s checkip.dyndns.org | awk '{ print $6 }' | cut -f1 -d'<'`
ip=`curl -s http://www.xpertdns.com/myip.php`
echo "current ip address is: $ip"
# Checks if IP address has changed
if [ $ip != $lastip ]; then
date=`date +%D\ %r`
# Writes new IP address (if it has changed) to file, and creates mail text.
echo $ip > $IPFILE
echo "$DOMAIN's IP address is now $ip as of $date" > $MAILFILE
echo "updating dyndns"
curl -s "https://www.xpertdns.com/dyndns.php?dynid=$DYNID&ip=$ip&uname=$UNAME&password=$PASSWORD"
echo ""
echo "IP changed so sending message..."
# Sends updated IP address to recipient. Change it as you need.
mail -s "IP address changed." $EMAIL < $MAILFILE
echo "logging the IP change to /var/log/ipTeller_ipchange.log"
echo "$date -- IP CHANGED TO: $ip" >> /var/log/ipTeller_ipchange.log
# Otherwise, if you still have the same IP address (lucky you!!!), it nicely exit with no action.
else
exit 0;
fi
exit;
######################################### END OF THE SCRIPT ################################################

