'Author: Martin Oehy
'Zweck: Kontrolliertes Update des DDNS bei DNSMadeEasy
'Info: IE6: Advanced: allow paste operations via script -> muss im IE disabled
' IE7: Security: Scripting: allow programmatic Clipbord access
Option Explicit
Dim g_oFso
Dim g_oShell
Set g_oFso = WScript.CreateObject("Scripting.FileSystemObject")
Set g_oShell = WScript.CreateObject("Wscript.Shell")
Const vbAnf = """"
Dim strOldIP, strNewIP, strIP
Dim strLogFile
Dim StrInputFile
Dim StrError
Dim arrAccounts, strAccounts, strAccount, strDDNSUSername, strDDNSPw
dim strLogFolder, strChangeFile , strIncludeFile
dim objIE
strLogFolder = "C:\AppData\Scripts\"
if not g_oFso.folderexists(strLogFolder) Then
strLogFolder = g_oShell.ExpandEnvironmentStrings("%temp%") & "\"
End If
strLogFile = strLogFolder & "DNSUpdate.log"
strChangeFile = strLogFolder & "DNSUpdateChange.log"
strIncludeFile = strLogFolder & "DNSUpdate.inc"
strOldIP = ""
strAccounts = "1111111;2222222" ' The numbers of your Accounts by DNSMadeEasy separated by ;
strDDNSUSername = "aaaaa" ' Logon Name at DDNS
strDDNSPw = "Password" ' Passwort by DDNS
if g_oFso.fileexists(strIncludeFile) then ' Letzte IP einlesen
include strIncludeFile
end if
Set objIE = CreateObject("InternetExplorer.Application")
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 300
objIE.Height = 180
objIE.Navigate("www.dnsmadeeasy.com/myip.jsp") ' Get IP
Do
Loop Until Not objIE.busy
'objIE.Visible = True
objIE.Document.execcommand "SelectAll"
objIE.Document.execcommand "Copy"
strIP = objIE.document.parentwindow.clipboardData.GetData("text")
objIE.Quit
set ObjIE = Nothing
strNewIP = ltrim(rTrim(strIP))
fuQuicklog01 strIncludeFile,"C","strOldIP=" & vbanf & strNewIP & vbAnf
'msgbox "Old:" &strOldIP & vbCRLF & "New:" &strNewIP
If strNewIP <> strOldIP Then ' test ob die IP geändert hat
FuQuicklog01 strLogFile ,"A",now() & vbTab & "Warning: IP Change to " & strNewIP
FuQuicklog01 strChangeFile ,"A",now() & vbTab & "Warning: IP Change to " & strNewIP
arrAccounts = split(strAccounts,";")
For Each strAccount in arrAccounts ' einen Account nach dem anderen Aktualisieren
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("www.dnsmadeeasy.com/servlet/updateip?username=" & strDDNSUSername & "&password=" & strDDNSPw & "&id=" & strAccount & "&ip=" & strNewIP)
do
Loop Until Not objIE.busy
'objIE.Visible = True
objIE.Document.execcommand "SelectAll"
objIE.Document.execcommand "Copy"
strError = objIE.document.parentwindow.clipboardData.GetData("text")
'msgbox "Wait"
objIE.Quit
Set objIE = Nothing
FuQuicklog01 strLogFile,"A",now() & vbTab & strAccount &" ReturnCode :" & strError
Next
Else
FuQuicklog01 strLogFile,"A",now() & vbTab & "Info: IP Not Changed " & strNewIP
End If
Public Function fuQuickLog01( ByVal strFileFQN, ByVal strMode, ByVal strTextline )
'********************************************************************************
' Author: 2008-07-22 Martin Oehy
' Beschreibung: Erstellt oder erweitert ein Logfile mit einer Zeile
'
' Parameter:
' strFileFQN : z.B c:\temp\logfile.txt
' strMode : C für Create oder A für Append
' strTextLine: Text der gelogt werden soll
' Return: -1 für Fehler
'
'********************************************************************************
'On Error Resume next
Dim foFSO
Dim foLogfile
Const Forappending = 8
Set foFSO=CreateObject("Scripting.FileSystemObject")
If UCase(strMode) = "C" Or Not foFSO.FileExists(strFileFQN) Then ' new or not existing
Err.Clear
set foLogfile = foFSO.CreateTextFile(strFileFQN,True)
If Err.Number > 0 Then
fuQuickLog01 = "1 " & Err.Description
Exit Function
End If
Else
Err.Clear
Set foLogFile = foFSO.OpenTextFile(strFileFQN, ForAppending)
If Err.Number > 0 Then
fuQuickLog01 = "1 " & Err.Description
Exit Function
End If
End If
foLogFile.WriteLine strTextLine
foLogFile.Close
Set foLogFile = Nothing
Set foFSO = Nothing
fuQuickLog01 = 0
End Function
Public Function Include(sInstFile)
' Author OM 2008-09-02 OM
' Include a VB with Public arguments
' Example Include File:
' Public strText
' strText = "This is a Message"
'
' For non public rewrite the SUB as Sub
On Error Resume Next
Dim foFSO, f, s
Set foFSO = CreateObject("Scripting.FileSystemObject")
If foFSO.FileExists(sInstFile) Then
Set f = foFSO.OpenTextFile(sInstFile)
s = f.ReadAll
f.Close
ExecuteGlobal s
End If
Set foFSO = Nothing
Set f = Nothing
End Function |