102010

External IP Address Notify Script Andrew Mallett | Updated July 2013

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

Comments (0)

Name
E-mail (Will not appear online)
Homepage
Title
Comment
;-) :-) :-D :-( :-o :-O B-) :oops: :-[] :-P
To prevent automated Bots form spamming, please enter the text you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
»
This comment form is powered by GentleSource Comment Script. It can be included in PHP or HTML files and allows visitors to leave comments on the website.

Temporary Email   Disposable Email   Throwaway Email