Jump to content

Check New IP and Email


 Share

Recommended Posts

I wrote the script for personal use, since my cable company likes to use Dynamic IP addressing on its network...so I can update my dns entries while out of the house, or just use the IP itself to get access...

#include <Inet.au3>
Dim $oMyError = ObjEvent ("AutoIt.Error", "ErrorHandler")

Global $youremail = "Some Person <someperson@organization.com>"
Global $smtpserver = "mail.organization.com"
Global $smtpuser = "mailusername"
Global $smtppass = "mailpassword"

#Region Do Not Change
HotKeySet("{ESC}", "QuitIPChecking")

While 1
$PublicIP = _GetIP()
$RegistryIP = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion", "PublicIP")
Select
        Case $RegistryIP = ""
            RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion", "PublicIP", "REG_SZ", $PublicIP)
            SendEmail()
        Case $RegistryIP <> $PublicIP
            SendEmail()
    EndSelect
WEnd

Func SendEmail()
    $objMessage = ObjCreate ("CDO.Message")
    With $objMessage
        .Subject = @ComputerName & "'s Public IP Address Has Changed"
        .Sender = $youremail
        .From = $youremail
        .To = $youremail
        .TextBody = @ComputerName & "'s IP Address has changed.  New IP Address: " & @CRLF & $PublicIP
    EndWith
    With $objMessage.Configuration.Fields
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $smtpserver
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $smtpuser
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $smtppass
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update
    EndWith
    $objMessage.Send
EndFunc  ;==>SendEmail

Func QuitIPChecking()
    Exit
EndFunc

Func ErrorHandler()
    
    $HexNumber = Hex($oMyError.number, 8)
    
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    
    SetError(1); to check for after this function returns
EndFunc  ;==>ErrorHandler
#EndRegion

Writing AutoIt scripts since

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

  • 1 year later...

I wrote the script for personal use, since my cable company likes to use Dynamic IP addressing on its network...so I can update my dns entries while out of the house, or just use the IP itself to get access...

#include <Inet.au3>
Dim $oMyError = ObjEvent ("AutoIt.Error", "ErrorHandler")

Global $youremail = "Some Person <someperson@organization.com>"
Global $smtpserver = "mail.organization.com"
Global $smtpuser = "mailusername"
Global $smtppass = "mailpassword"

#Region Do Not Change
HotKeySet("{ESC}", "QuitIPChecking")

While 1
$PublicIP = _GetIP()
$RegistryIP = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion", "PublicIP")
Select
        Case $RegistryIP = ""
            RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion", "PublicIP", "REG_SZ", $PublicIP)
            SendEmail()
        Case $RegistryIP <> $PublicIP
            SendEmail()
    EndSelect
WEnd

Func SendEmail()
    $objMessage = ObjCreate ("CDO.Message")
    With $objMessage
        .Subject = @ComputerName & "'s Public IP Address Has Changed"
        .Sender = $youremail
        .From = $youremail
        .To = $youremail
        .TextBody = @ComputerName & "'s IP Address has changed.  New IP Address: " & @CRLF & $PublicIP
    EndWith
    With $objMessage.Configuration.Fields
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $smtpserver
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $smtpuser
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $smtppass
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update
    EndWith
    $objMessage.Send
EndFunc ;==>SendEmail

Func QuitIPChecking()
    Exit
EndFunc

Func ErrorHandler()
    
    $HexNumber = Hex($oMyError.number, 8)
    
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    
    SetError(1); to check for after this function returns
EndFunc ;==>ErrorHandler
#EndRegion

GETTING UNKNOWN FUNCTION NAMES ERRORS ON LINE 2 and 25

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
 Share

  • Recently Browsing   0 members

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