================
Public IP Change
================
Windows Version: Here (Or use CYGWIN with this linux script – not tested)
For: Any Linux (Tested on Debian 6)
 
=== Some random info ===
 
Lots of people alot of money to get static IP address. There are alot of benefits to having the same Static IP. If you have your IP tied to a Domain, and it changes, even if you update it, it could take up to 24 (or 48 hours) to update through out the DNS servers. This could be very hazardous to business etc. The best solution is definatly having a none changing ip. Some of us arent that lucky though. So the solution is to have your system update you when the public IP changes.
 
I have two methods that keep updating me. The second way is optional. 
 
The first way checks if the IP changes and emails me (I have it email to my phone via sms text message and my email)
 
The second optional way is that I just have my system update me of my IP 3 times everyday via email (again to my phone via sms text message and my email)
 
I use the sms gateway email of my phone service provider to send an email, it then forwards a text message to my phone. I will provide a list of the phone service providers different sms & mms gateways later on.
 
=== Tools I use ===
 
For the operations of the code I just use BASH script. For scheduling I use cron jobs. For my system to email me, I use postfix.
To get current IP:
 

 
=== INSTRUCTIONS ====
 
=== Step 1 : Postfix – System Emails ===
 
 
When asked for what kind of email server select “Internet Site”
Leave everything at default
 
Test the email like so
First type “# mail destination@email.com”
Then in the subject put “TEST” and hit enter
Then type the email body “This is a test message” and hit enter and type a dot/period “.”. Te period is a EOT character. EOT meaning End of Transmitions notifies the system that the email is complete.
 
Another way to email
 
=== Step 2 : Make the apps location ===
 
First log in as root
And go to roots home directory 
NOTE: in my examples this is /root/
 
Make the ipchange folder where the apps will go and inside it the log folder where the logs will go 
NOTE: in my examples this is /root/ipchange and /root/ipchange/logs
=== Step 3a : Write the 2 scripts ===
I use vim (when inside it hit “i” to start typing, and then “esc” to stop typing, once out of the typing mode, aka insert mode, type “:wq!” to save and exit”). Then I verify the scripts with cat command.
 
If you dont have vim type apt-get install vim 
 
Make the file and give it the proper execution attributes. 
 
Now that the scripts are made and can be execute, its time to write the instructions into them.
=== Step 3b : Write the ipchange.sh script ===
 
This script will send the new ip by email if it has changed. It gets the IP and saves it to a file, next time it runs it checks to see if that file has the same or different value. If the value is different, then it must be a new IP so it emails it. 
Type “i” to enter insert mode
Type the following (in between the tidle break lines, obviously dont include the tidle break lines):
Note: change the EMAIL1, EMAIL2, and EMAIL3 to 3 different emails. I have EMAIL3 send it to my phone where 5551234321 is my phone number and tmomail.net is the text gateway of my phoneprovider (I have a list of the phone gateways at the bottom)
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Type “Escape” to quit insert mode
Then type “:wq!” to force save anf quit.
 
=== Step 3c : Write the iplog.sh script ===
 
This script emails the current IP to the email.
Type “i” to enter insert mode
Type the following (in between the tidle break lines, obviously dont include the tidle break lines):
 
Note: change the EMAIL1, EMAIL2, and EMAIL3 to 3 different emails. I have EMAIL3 send it to my phone where 5551234321 is my phone number and tmomail.net is the text gateway of my phoneprovider (I have a list of the phone gateways at the bottom)
Note: to find out the email (sms or mms gateway) for your phone/telecom provider check out my list here: http://www.infotinks.com/list-of-sms-mms-gateways-for-phone-companys/
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Type “Escape” to quit insert mode
Then type “:wq!” to force save anf quit.
 
=== Step 4 : Setup the Cronjob ===
 
In linux cron jobs run scheduled tasks.
 
Every user has cron jobs. Google “cron examples” to learn more. For now we will make a cronjob that runs as root, these run in the background.
 
To see all the current root cron tasks type # crontab -l. Dont be surprised if you have none. There are actually more cronjobs that just that. The other ones usually go to /etc/cron.d
 
To edit crontabs run the command below, it might ask what editor to use, Just use vim or vi, or nano/pico. If you use nano/pico (Save is: Control-O then enter enter, and Quiting is Control-X) 
 
Add the following lines into it(at the bottom) and save and exit:
 
NOTE how you can use # hash symbols in crontabs to comment stuff out
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
=== THE END ====
 
Final folder structure in my examples is like so
 
/root/ipchange/ipchange.sh
/root/ipchange/iplog.sh
/root/ipchange/logs/<logs will go here>
 
-OPTIONAL STEP-
 
Now all this should just run
 
But just incase reload the cron job (optional, cron automatically check its crontabs so this step is unnecessary) 
=== List of other sms gateways ===
 Check out the list of other sms/mms gateways here

2 thoughts on “Script Email/Text Current Public IP & email/SMS or MMS text when Public IP Changes

    1. Im not sure what a “Yellow Dog” is. However if its a phone, then yes as long as its supports incoming sms text (you will just need to find out the email address associated with SMS texting your phone **see below**). If its a linux distro, then yes you can use this method as long as it has internet access, the mail command, and curl command.

      ** For example texting a Tmobile provided cell phone (any model of phone that support SMS text) which has the phone number 8015551234 then the email address is 8015551234@tmomail.net.

Leave a Reply

Your email address will not be published. Required fields are marked *