Jump to content

WanIP notifier - update


Recommended Posts

I had posted this earlier in the year (previous post), but always had problems depending on who I installed it for and what isp they were using. Always had to go into the code to change stuff specific to the customers needs. I've been working on it off and on since then and I think I have it right. I'd like some input or suggestions if anyone has the time.

Basically the core program itself is generic, nothing specific in it. It simply downloads a web page to a file, then emails the contents of that file to an email address. All is specified in an editable ini file.


[WAN IP Site]
; Full url of page that displays public ip address in one line format.
; ie. http://www.whatismyip.org

; Equals number of email addresses configured to send ip address to.
; A section must be created for each email address desired. 
; ie. [Settings1], [Settings2], ... [Settings999]

; Self explanatory.
; Self explanatory.
; Ip address or smtp name of mail server.  Default port is 25, but
; best to specify it.  ie.  mail.domainname.com:25
; SMTP server authenitcation settings.
; Default setting is 1.
; If different or blank, wanip will use the entries to send email
; through above smtp server.


I've actually created my own wanip displaying page that's done in asp. I use it instead of whatismyip.org.


<% Response.Write Request.ServerVariables("REMOTE_ADDR") %>

This is the actual script.


;          Find WAN iP-address - email if changed

$Site = IniRead(@Homedrive & "wanip.ini", "WAN IP Site", "Site", "")
$FILE = FileOpen(@Homedrive & "wanip.txt", 0)
$LINE1 = FileReadLine($FILE)

$IP = URLDownloadToFile ($Site, @Homedrive & "wanip.txt")

$FILE = FileOpen(@Homedrive & "wanip.txt", 0)
$LINE = FileReadLine($FILE)
FileClose(@Homedrive & "wanip.txt")

If $Line1 = $Line Then

$Settings = IniRead(@Homedrive & "wanip.ini", "Settings", "Settings", "")

While $I<=$Settings
$To = IniRead(@Homedrive & "wanip.ini", "Settings" & $I, "To", "")
$From = IniRead(@Homedrive & "wanip.ini", "Settings" & $I, "From", "")
$SMTP = IniRead(@Homedrive & "wanip.ini", "Settings" & $I, "SMTP", "")
$UN = IniRead(@Homedrive & "wanip.ini", "Settings" & $I, "UN", "")
$PW = IniRead(@Homedrive & "wanip.ini", "Settings" & $I, "PW", "")

FileDelete(@HomeDrive & $To & ".txt")

If $UN=1 Then
RunWait(@ComSpec & " /c " & 'blat wanip.txt -debug -log ' & $To & '.txt -to ' & $To & ' -f ' & $From & ' -server ' & $SMTP, "", @SW_HIDE)

RunWait(@ComSpec & " /c " & 'blat wanip.txt -debug -log ' & $To & '.txt -to ' & $To & ' -f ' & $From & ' -server ' & $SMTP & ' -u ' & $UN & ' -pw ' & $PW, "", @SW_HIDE)    



Basically does this:

1. Copies current contents of wanip.txt to variable.

2. Downloads webpage containing public ip address to wanip.txt and places contents in variable.

3. Compares two variables, if same, exits.

4. Grabs info from ini file.

5. Uses blat to send wanip.txt to proper recipient. (outputs to a log file prefixed with the to address).

6. Loops the sending routine for as many email addresses as needed.

Blat can be downloaded here:


Place wanip.au3, wanip.ini, and blat.exe in the same folder. I usually schedule it to run every ten or fifteen minutes.

Believe it or not I tightened down this code from about 250 lines. I wanted the script to be able to not use authentication if the un in the ini was simply blank, but I couldn't find the right code, so I had to make it skip authentication if un=1. Kind of frustrating.

If anyone has any suggestions I'd be glad to hear it.

Link to comment
Share on other sites

try to write it in pure au3 and avoid temp files.

i would do it like this:

to get the file: _INetGetSource()

filter out the ip: Regexp (less send = less bandwidth needed)

to send the file: TcpSend()

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

There is a Com object that's been floating around here for the longest time...yet no one uses it ;)

I guess I'll post it once again...

Uses defaults for mail settings (port, timeout, etc)

Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

MSLx, nice script. But from what I can tell by looking, it only works if your computer is assigned the public ip address. I needed something that would work behind a router on a machine with a private ip. A lot of my customers are on DSL and it was getting frustrating having to call them to ask them what their ip is so i could remote desktop into a server.

w0uter, I'll take a look at the beta version. I'd love to not have to use blat to send the email! And although I could obviously incorporate the info in the ini file into the script itself, I wanted something that I could deplay at a customer quickly without having to edit and recompile the code.

Anyone have a suggestion on my problem with instead of leaving the un and pw lines blank having to use 1 in the ini file when no authentication is necessary? Something along the lines of:

If $UN=null then
 Send email with no authentication
 Send email with authentication
Link to comment
Share on other sites

Acutally, I run it on my home computer all the time, right behind a linsys router. I've never had a problem with it. To get the WAN-IP, it goes to the website to get it (REMOTE_ADDR in $_SERVER php constant most likely) to grab it, and then just stores it in a reg key for future.

If the IP ever changed, or you don't have it yet, just through the script on the machine, and check your email momentarily, you have your IP address.

Edit: I just noticed that it will send emails indefinately to the email address...I'll rewrite in a minute and post it in this post


Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

As long as it is a standard-authentication SMTP server, it will work. If it requires NTLM authenication, other changes have to be made (I've never done that, you'd have to look into the COM object for that). I'll register for a yahoo address and test if for you...

Hum...need to pay for pop access...Anyways, you should be able to just use the smtp settings, but my guess is that the $youremail needs to be the yahoo address. I'll update the code to allow for different send/recieve email addresses. That's most likely the problem...

Change any of the settings you need, and it should work now


Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...