Sign in to follow this  
Followers 0
dreniarb

WanIP notifier - update

23 posts in this topic

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.

WANIP.INI

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

[Settings]
; 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]
Settings=2

[Settings1]
; Self explanatory.
To=recipient@domain.com
; Self explanatory.
From=dynipcust@domain.com
; Ip address or smtp name of mail server.  Default port is 25, but
; best to specify it.  ie.  mail.domainname.com:25
SMTP=mail.domain.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.
UN=1
PW=1

[Settings2]
To=diffrecp@domain.com
From=dynipcust@domain.com
SMTP=mail.domain.com:25
UN=smtpusername
PW=smtppassword

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

WANIP.ASP

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

This is the actual script.

WANIP.AU3

;---------------------------------------------------------------
;          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
    Exit
EndIf   

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

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)

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

$I=$I+1

WEnd

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:

Blat

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

TCPSend is only in the beta version, right?

Share this post


Link to post
Share on other sites

TCPSend is only in the beta version, right?

Right.


FootbaG

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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())

Share this post


Link to post
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
Else
 Send email with authentication
EndIf

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Get_Email_Public_IP.au3

Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

What if you have more than one email address you want to send it to? I have some customers who work from home and use the program so they know what the ip address is. I have it email me and them.

Share this post


Link to post
Share on other sites

easy, run the script 2ce with 2 diff emails.

hard, edit so that it mails to 2 emails.

That or mod the script to run the Com object function FOR each email ;)


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

How do u make it work? i tried with yahoo like:

Global $youremail = "Me@hotmail.com"

Global $smtpserver = "mail.yahoo.com"

Global $smtpuser = "Me@yahoo.co.uk"

Global $smtppass = "******"

Edited by D4rk^S0ul

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Get_Email_Public_IP.au3

Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Thx because i couldnt get to work for yahoo ;) wasent sure if i was doin something wrong.. does any1 know wat smtp servers work?

Share this post


Link to post
Share on other sites

updated previous post...


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

.To = $recipient

Error: Varible used without being declared

?? I get this error when sendin the email?

Share this post


Link to post
Share on other sites

Hehe, my spelling is bad, change Global $recipent to Global $recipient

;)


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

lol its amazin how 1 little misstake can make somethin go to hell ;) thx dude now lets hope works for me i bet it wont nothin against u just i most unlucky person in world :P

Should it work if i hot key to SendEmail?

Share this post


Link to post
Share on other sites

I get a error about a min or two after running sendemail function i attached pik of error:

Share this post


Link to post
Share on other sites

That's most likely an error with the configuration settings, as it errors on the send method...


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Is there a way i can change the settings to not do this?

Share this post


Link to post
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
Sign in to follow this  
Followers 0