Author Topic: HOW TO: Send yourself an email when your home ip address changes.  (Read 1927 times)

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2851
    • View Profile
    • Codecore Technologies
Would you like to know when your home ip address changes?  Most residential internet providers use dynamic ip addresses so your home ip address can change over time. This rule will send yourself an email containing your new ip address whenever it detects that it has changed.

Device Requirements:

  vars: A global variable device used to store the ip address for later comparison.
  http: An http (hyper text transfer protocol) device used to retrieve your ip address.
  smtp: An email sender (smtp) device to email the new ip address to yourself.

This rule uses whatismyip.com to retrieve your ip address. Please review that site's automation policies HERE.

Rule Name: Check Home IP Address
Group Name:
Description: Send yourself an email when your home ip address changes.
Enabled: Yes
Log: No

Event:
  Device Name: Date & Time  (dates)
  Event Name: Every # of Hours

Whenever Filters:
  DaysOfWeek: SMTWTFS
  Hours: 6

Although this can be done with the action list editor grammar, the following example uses j9Script:
For those of you avid programmers, you will wonder why the if statement logic is so goofy below. It's because j9Script does not currently support short-circuit-if statements so if you don't have the global variable defines, a simple OR if statement would error.

Code: [Select]
// Get your ip address.
s = http.RetrieveWebPage( "http://automation.whatismyip.com/n09230945.asp" );

// Determine if it changed.
changed = false;
if (vars.IsDefined( "homeipaddress" ) == false)
changed = true;
else if (vars.homeipaddress != s)
changed = true;

// If it changed then remember it in a global variable and send an email.
if (changed)
{
vars.homeipaddress = s;
smtp.SendEmail( "you@example.com", "Home IP Address", "You home IP address has changed to: " + s );
}

Johnny
« Last Edit: May 07, 2012, 01:05:42 pm by John Hughes »
John Hughes
Codecore Technologies

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2851
    • View Profile
    • Codecore Technologies
Re: HOW TO: Send yourself an email when your home ip address changes.
« Reply #1 on: May 07, 2012, 01:06:08 pm »
I updated the web address used to get the ip address since it changed.
John Hughes
Codecore Technologies