102010

External IP Address Notify Script Andrew Mallett | Updated July 2017

This script is a development of the External IP Address Monitor. It checks the external IP at two minutes past midnight, logs it as before, then compares it to the previous day's IP. If the external IP Address has changed, the script sends an administrative alert via email.

cd /sc/extip
rm /sc/extip/ipold.php
mv /sc/extip/ip.php /sc/extip/ipold.php
wget http://shell-scripts.com/ip.php
echo `/bin/date +%Y-%m-%d` `/bin/cat /sc/extip/ip.php` >> /sc/extip/ip_record

if [ $(cat /sc/extip/ip.php) = $(cat /sc/extip/ipold.php) ]; then
echo

else

/sc/scripts/extip_email.sh

fi

The above code firstly changes to the working directory /sc/extip and deletes ipold.php, which contained the IP record for the day before yesterday (this script runs at 00:02 hours in the morning).

Line 3 then moves yesterday's IP record ip.php to ipold.php

Line 4 grabs the new IP address from the web server, puts it into a new ip.php file and updates the ip_record in line 5..

The if-else statement compares today's ip.php with yesterday's ipold.php to see if they are the same. If the are, it echoes nothing and finishes. If they are different then the statement else's out to send an email (or even an SMS) via the email script - extip_email.sh .

 

Back