How to Get an Email Notification if Your Local IP Address Changes
d. bodnar 8-21-09

 

Those of us who need to gain remote access to our home computers need to know if our Internet service provider changes our local IP address.  You can use this procedure and these programs to generate an email to you every time that your local IP address changes.

Overview

Getting Your Current IP Address

There are any number of web pages that will report your local IP address when you access them.  These include:

http://whatismyipaddress.com/  and http://whatismyip.com

These sites frequently report more information than we need.  I have also found them to change their format and to be unavailable from time-to-time.

For these reasons I created a page on my web server that uses a PHP script to report only the IP address in numerical format.

http://davebodnar.com/showip2.php

The contents of this web page is:

<?php echo $_SERVER['REMOTE_ADDR']; ?>

Pretty simple, eh?

What Runs on your PC

An executable Quick Basic 4.5 program takes care of automating the process.  The code is shown here

'd. bodnar 7-17-07 'revised to use PHP code on DGB.com to get ip

'uses php code to get ip and vmailer to email to gmail if changed

CLS SHELL "copy ip.txt ip_old.txt"

SHELL "wget http://davebodnar.com/showip2.php -O ip.txt"

OPEN "i", 1, "ip.txt" LINE INPUT #1, c$
CLOSE #1
PRINT a$

OPEN "a", 1, "trace.log"
PRINT #1, DATE$, TIME$, c$
CLOSE #1

OPEN "i", 1, "ip_old.txt"
LINE INPUT #1, old$
CLOSE #1

PRINT "new ip, old ip", c$, old$
IF c$ = old$ THEN
    PRINT "same"
    ELSE
    PRINT "changed"
    GOTO sendit:
END IF
END

sendit:
CLOSE
OPEN "o", 1, "email.txt"
PRINT #1, "To:bodnar@gmail.com"
PRINT #1, "From:DaveBodnar@verizon.net"
PRINT #1, "Subject: NEW IP " + c$ + " " + DATE$ + " " + TIME$
PRINT #1, " "
PRINT #1,
PRINT #1, "New IP address as of ", DATE$, " ", TIME$
PRINT #1, "now: ", c$
CLOSE

SHELL "vmailer email.txt outgoing.verizon.net bodnar@gmail.com davebodnar@verizon.net davebodnar password99"

Notes on the program:

CLS SHELL "copy ip.txt ip_old.txt" copies the last IP address that was found so that we can compare the new one to it
SHELL "wget http://davebodnar.com/showip2.php -O ip.txt" calls "wget" which is a DOS based program that gets the content of a web page and saves it to a file.  In this case it is called "ip.txt"
OPEN "i", 1, "ip.txt" LINE INPUT #1, c$
CLOSE #1
PRINT a$

OPEN "a", 1, "trace.log"
PRINT #1, DATE$, TIME$, c$
CLOSE #1

OPEN "i", 1, "ip_old.txt"
LINE INPUT #1, old$
CLOSE #1

Reads the last IP read (ip_old) and the current address.  the middle section writes the log of IP addresses.
PRINT "new ip, old ip", c$, old$
IF c$ = old$ THEN
    PRINT "same"
    ELSE
    PRINT "changed"
    GOTO sendit:
END IF
END
Determines if the IP has changed.  If not the program ends.  If it has changed it goes to the next section.
sendit:
CLOSE
OPEN "o", 1, "email.txt"
PRINT #1, "To:bodnar@gmail.com"
PRINT #1, "From:DaveBodnar@verizon.net"
PRINT #1, "Subject: NEW IP " + c$ + " " + DATE$ + " " + TIME$
PRINT #1, " "
PRINT #1,
PRINT #1, "New IP address as of ", DATE$, " ", TIME$
PRINT #1, "now: ", c$
CLOSE
Creates an email file "email.txt" that contains the new IP address.  Be sure to change the email To: address and from: assress
SHELL "vmailer email.txt outgoing.verizon.net bodnar@gmail.com davebodnar@verizon.net davebodnar password99" Uses the "vmailer" program to send the email.  Be sure to change the email address (to and from), the login name and the password

Programs

QB45 program - no longer for sale but available from sites on the Internet.  Load the program into QB45 and compile it into a stand alone executable program.

QB45 Basic file - note that this file is titled Traceip3.txt.  It must be renamed TraceIP3.BAS to be used in QB45.  Make sure you edit it to reflect your email information and password

WGET - http://users.ugent.be/~bpuype/wget/  (I use version 1.10.2)  -a DOS based program that gets the content of a web page and saves it to a file.

VMAILER - http://www.virdi-software.com/vmailer/desc.shtml - a DOS based program that sends an email from a text file

Making it Work

Put all of the files into the same directory, including the QB45 executable that you made from the Traceip3.txt file.

Set a Scheduled Task in Windows (Start / Programs / Accessories / System Tools / Scheduled Task) to execute TraceIP.exe each hour.

The log file (trace.log) will be updated in that directory each hour.